From 15aea91fcb321f4e9f608ce6a407802ed3e0d2cb Mon Sep 17 00:00:00 2001 From: zelvad Date: Fri, 26 Jan 2024 16:53:00 +0200 Subject: [PATCH] feat: support for spatie/laravel-medialibrary v11 has been added --- .gitignore | 2 +- composer.json | 9 +- dist/js/field.js | 2 +- dist/mix-manifest.json | 2 +- phpunit.xml | 5 +- .../Modals/ChooseExistingMedia.vue | 8 +- .../Medialibrary/Modals/Cropper.vue | 4 +- routes/api.php | 16 ++ src/Actions/MediaAttachAction.php | 63 +++++ src/Actions/MediaAttachmentListAction.php | 89 ++++++ src/Actions/MediaCropAction.php | 60 ++++ src/Actions/MediaListAction.php | 54 ++++ src/Actions/MediaRegenerateAction.php | 34 +++ src/Actions/MediaSortAction.php | 22 ++ src/Data/MediaAttachData.php | 21 ++ src/Data/MediaAttachmentListData.php | 23 ++ src/Data/MediaCropData.php | 19 ++ src/Data/MediaListData.php | 18 ++ src/Data/MediaSortData.php | 13 + src/FieldServiceProvider.php | 47 ++-- src/Fields/GeneratedConversions.php | 19 +- src/Fields/Medialibrary.php | 262 ++++++++---------- src/Fields/Support/AttachCallback.php | 4 +- .../Support/AttachableMediaPresenter.php | 2 +- src/Fields/Support/MediaCollectionRules.php | 2 +- src/Fields/Support/MediaFields.php | 43 ++- src/Fields/Support/MediaPresenter.php | 77 +++-- src/Http/Controllers/AttachController.php | 76 ----- src/Http/Controllers/AttachableController.php | 53 ---- src/Http/Controllers/CropController.php | 58 ---- src/Http/Controllers/IndexController.php | 29 -- .../Controllers/MediaAttachController.php | 20 ++ .../MediaAttachmentListController.php | 22 ++ src/Http/Controllers/MediaCropController.php | 22 ++ src/Http/Controllers/MediaListController.php | 20 ++ .../Controllers/MediaRegenerateController.php | 23 ++ src/Http/Controllers/MediaSortController.php | 20 ++ src/Http/Controllers/RegenerateController.php | 19 -- src/Http/Controllers/SortController.php | 13 - src/Http/Requests/MediaAttachRequest.php | 75 +++++ .../Requests/MediaAttachmentListRequest.php | 59 ++++ src/Http/Requests/MediaCropRequest.php | 62 +++++ src/Http/Requests/MediaListRequest.php | 25 ++ ...dialibraryRequest.php => MediaRequest.php} | 6 +- src/Http/Requests/MediaSortRequest.php | 38 +++ .../ResolveFromDependencyContainerFields.php | 13 +- .../HasMedialibraryField.php | 29 +- .../ResolveFromFlexibleLayoutFields.php | 46 +-- src/MedialibraryFieldResolver.php | 36 ++- src/{ => Models}/TransientModel.php | 61 ++-- src/PruneStaleMedia.php | 24 -- src/Resources/Media.php | 22 +- src/helpers.php | 58 +--- tests/Integration/AttachControllerTest.php | 20 +- tests/Integration/CropControllerTest.php | 10 +- tests/Integration/IndexControllerTest.php | 2 +- tests/Integration/PruneStaleMediaTest.php | 28 -- tests/Integration/SortControllerTest.php | 34 ++- tests/TestCase.php | 3 + tests/Unit/HelpersTest.php | 103 +------ tests/Unit/MedialibraryRequestTest.php | 18 +- 61 files changed, 1263 insertions(+), 804 deletions(-) create mode 100644 routes/api.php create mode 100644 src/Actions/MediaAttachAction.php create mode 100644 src/Actions/MediaAttachmentListAction.php create mode 100644 src/Actions/MediaCropAction.php create mode 100644 src/Actions/MediaListAction.php create mode 100644 src/Actions/MediaRegenerateAction.php create mode 100644 src/Actions/MediaSortAction.php create mode 100644 src/Data/MediaAttachData.php create mode 100644 src/Data/MediaAttachmentListData.php create mode 100644 src/Data/MediaCropData.php create mode 100644 src/Data/MediaListData.php create mode 100644 src/Data/MediaSortData.php delete mode 100644 src/Http/Controllers/AttachController.php delete mode 100644 src/Http/Controllers/AttachableController.php delete mode 100644 src/Http/Controllers/CropController.php delete mode 100644 src/Http/Controllers/IndexController.php create mode 100644 src/Http/Controllers/MediaAttachController.php create mode 100644 src/Http/Controllers/MediaAttachmentListController.php create mode 100644 src/Http/Controllers/MediaCropController.php create mode 100644 src/Http/Controllers/MediaListController.php create mode 100644 src/Http/Controllers/MediaRegenerateController.php create mode 100644 src/Http/Controllers/MediaSortController.php delete mode 100644 src/Http/Controllers/RegenerateController.php delete mode 100644 src/Http/Controllers/SortController.php create mode 100644 src/Http/Requests/MediaAttachRequest.php create mode 100644 src/Http/Requests/MediaAttachmentListRequest.php create mode 100644 src/Http/Requests/MediaCropRequest.php create mode 100644 src/Http/Requests/MediaListRequest.php rename src/Http/Requests/{MedialibraryRequest.php => MediaRequest.php} (73%) create mode 100644 src/Http/Requests/MediaSortRequest.php rename src/{ => Models}/TransientModel.php (75%) delete mode 100644 src/PruneStaleMedia.php delete mode 100644 tests/Integration/PruneStaleMediaTest.php diff --git a/.gitignore b/.gitignore index a5c9cc7..08689f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /.idea -/vendor +/vendor_old /node_modules package-lock.json composer.phar diff --git a/composer.json b/composer.json index f5b307c..fbf4192 100644 --- a/composer.json +++ b/composer.json @@ -21,14 +21,15 @@ } ], "require": { - "php": "^7.4|^8.0|^8.1", - "spatie/laravel-medialibrary": "^8.0|^9.0|^10.0|^11.0" + "php": "^8.2", + "spatie/laravel-medialibrary": "^11.0", + "spatie/laravel-data": "^3.0" }, "require-dev": { "laravel/nova": "^4.0", - "orchestra/testbench": "^5.0|^6.0|^7.0", + "orchestra/testbench": "^6.0|^7.0|^8.0", "nunomaduro/collision": "^4.0|^5.0|^6.0", - "phpunit/phpunit": "^8.5|^9.0" + "phpunit/phpunit": "^9.0" }, "autoload": { "psr-4": { diff --git a/dist/js/field.js b/dist/js/field.js index df97fc5..8380880 100644 --- a/dist/js/field.js +++ b/dist/js/field.js @@ -1,2 +1,2 @@ /*! For license information please see field.js.LICENSE.txt */ -(()=>{var t,r={9680:(t,e,r)=>{function n(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var o=n(r(3945)),i=r(3454),a=n(r(9996));function c(){return(c=Object.assign||function(t){for(var e=1;e0&&"back_forward"===window.performance.getEntriesByType("navigation")[0].type},r.handleBackForwardVisit=function(t){var e=this;window.history.state.version=t.version,this.setPage(window.history.state,{preserveScroll:!0,preserveState:!0}).then((function(){e.restoreScrollPositions(),b(t)}))},r.locationVisit=function(t,e){try{window.sessionStorage.setItem("inertiaLocationVisit",JSON.stringify({preserveScroll:e})),window.location.href=t.href,m(window.location).href===m(t).href&&window.location.reload()}catch(t){return!1}},r.isLocationVisit=function(){try{return null!==window.sessionStorage.getItem("inertiaLocationVisit")}catch(t){return!1}},r.handleLocationVisit=function(t){var e,r,n,o,i=this,a=JSON.parse(window.sessionStorage.getItem("inertiaLocationVisit")||"");window.sessionStorage.removeItem("inertiaLocationVisit"),t.url+=window.location.hash,t.rememberedState=null!=(e=null==(r=window.history.state)?void 0:r.rememberedState)?e:{},t.scrollRegions=null!=(n=null==(o=window.history.state)?void 0:o.scrollRegions)?n:[],this.setPage(t,{preserveScroll:a.preserveScroll,preserveState:!0}).then((function(){a.preserveScroll&&i.restoreScrollPositions(),b(t)}))},r.isLocationVisitResponse=function(t){return t&&409===t.status&&t.headers["x-inertia-location"]},r.isInertiaResponse=function(t){return null==t?void 0:t.headers["x-inertia"]},r.createVisitId=function(){return this.visitId={},this.visitId},r.cancelVisit=function(t,e){var r=e.cancelled,n=void 0!==r&&r,o=e.interrupted,i=void 0!==o&&o;!t||t.completed||t.cancelled||t.interrupted||(t.cancelToken.cancel(),t.onCancel(),t.completed=!1,t.cancelled=n,t.interrupted=i,y(t),t.onFinish(t))},r.finishVisit=function(t){t.cancelled||t.interrupted||(t.completed=!0,t.cancelled=!1,t.interrupted=!1,y(t),t.onFinish(t))},r.resolvePreserveOption=function(t,e){return"function"==typeof t?t(e):"errors"===t?Object.keys(e.props.errors||{}).length>0:t},r.visit=function(t,r){var n=this,i=void 0===r?{}:r,a=i.method,s=void 0===a?e.n$.GET:a,l=i.data,p=void 0===l?{}:l,h=i.replace,y=void 0!==h&&h,b=i.preserveScroll,w=void 0!==b&&b,x=i.preserveState,_=void 0!==x&&x,E=i.only,O=void 0===E?[]:E,S=i.headers,C=void 0===S?{}:S,k=i.errorBag,j=void 0===k?"":k,A=i.forceFormData,P=void 0!==A&&A,N=i.onCancelToken,T=void 0===N?function(){}:N,D=i.onBefore,M=void 0===D?function(){}:D,B=i.onStart,L=void 0===B?function(){}:B,R=i.onProgress,I=void 0===R?function(){}:R,U=i.onFinish,F=void 0===U?function(){}:U,V=i.onCancel,z=void 0===V?function(){}:V,H=i.onSuccess,W=void 0===H?function(){}:H,q=i.onError,$=void 0===q?function(){}:q,Y=i.queryStringArrayFormat,G=void 0===Y?"brackets":Y,X="string"==typeof t?d(t):t;if(!function t(e){return e instanceof File||e instanceof Blob||e instanceof FileList&&e.length>0||e instanceof FormData&&Array.from(e.values()).some((function(e){return t(e)}))||"object"==typeof e&&null!==e&&Object.values(e).some((function(e){return t(e)}))}(p)&&!P||p instanceof FormData||(p=f(p)),!(p instanceof FormData)){var Z=v(s,X,p,G),K=Z[1];X=d(Z[0]),p=K}var J={url:X,method:s,data:p,replace:y,preserveScroll:w,preserveState:_,only:O,headers:C,errorBag:j,forceFormData:P,queryStringArrayFormat:G,cancelled:!1,completed:!1,interrupted:!1};if(!1!==M(J)&&function(t){return g("before",{cancelable:!0,detail:{visit:t}})}(J)){this.activeVisit&&this.cancelVisit(this.activeVisit,{interrupted:!0}),this.saveScrollPositions();var Q=this.createVisitId();this.activeVisit=c({},J,{onCancelToken:T,onBefore:M,onStart:L,onProgress:I,onFinish:F,onCancel:z,onSuccess:W,onError:$,queryStringArrayFormat:G,cancelToken:o.CancelToken.source()}),T({cancel:function(){n.activeVisit&&n.cancelVisit(n.activeVisit,{cancelled:!0})}}),function(t){g("start",{detail:{visit:t}})}(J),L(J),o({method:s,url:m(X).href,data:s===e.n$.GET?{}:p,params:s===e.n$.GET?p:{},cancelToken:this.activeVisit.cancelToken.token,headers:c({},C,{Accept:"text/html, application/xhtml+xml","X-Requested-With":"XMLHttpRequest","X-Inertia":!0},O.length?{"X-Inertia-Partial-Component":this.page.component,"X-Inertia-Partial-Data":O.join(",")}:{},j&&j.length?{"X-Inertia-Error-Bag":j}:{},this.page.version?{"X-Inertia-Version":this.page.version}:{}),onUploadProgress:function(t){p instanceof FormData&&(t.percentage=Math.round(t.loaded/t.total*100),function(t){g("progress",{detail:{progress:t}})}(t),I(t))}}).then((function(t){var e;if(!n.isInertiaResponse(t))return Promise.reject({response:t});var r=t.data;O.length&&r.component===n.page.component&&(r.props=c({},n.page.props,r.props)),w=n.resolvePreserveOption(w,r),(_=n.resolvePreserveOption(_,r))&&null!=(e=window.history.state)&&e.rememberedState&&r.component===n.page.component&&(r.rememberedState=window.history.state.rememberedState);var o=X,i=d(r.url);return o.hash&&!i.hash&&m(o).href===i.href&&(i.hash=o.hash,r.url=i.href),n.setPage(r,{visitId:Q,replace:y,preserveScroll:w,preserveState:_})})).then((function(){var t=n.page.props.errors||{};if(Object.keys(t).length>0){var e=j?t[j]?t[j]:{}:t;return function(t){g("error",{detail:{errors:t}})}(e),$(e)}return g("success",{detail:{page:n.page}}),W(n.page)})).catch((function(t){if(n.isInertiaResponse(t.response))return n.setPage(t.response.data,{visitId:Q});if(n.isLocationVisitResponse(t.response)){var e=d(t.response.headers["x-inertia-location"]),r=X;r.hash&&!e.hash&&m(r).href===e.href&&(e.hash=r.hash),n.locationVisit(e,!0===w)}else{if(!t.response)return Promise.reject(t);g("invalid",{cancelable:!0,detail:{response:t.response}})&&u.show(t.response.data)}})).then((function(){n.activeVisit&&n.finishVisit(n.activeVisit)})).catch((function(t){if(!o.isCancel(t)){var e=g("exception",{cancelable:!0,detail:{exception:t}});if(n.activeVisit&&n.finishVisit(n.activeVisit),e)return Promise.reject(t)}}))}},r.setPage=function(t,e){var r=this,n=void 0===e?{}:e,o=n.visitId,i=void 0===o?this.createVisitId():o,a=n.replace,c=void 0!==a&&a,s=n.preserveScroll,u=void 0!==s&&s,l=n.preserveState,f=void 0!==l&&l;return Promise.resolve(this.resolveComponent(t.component)).then((function(e){i===r.visitId&&(t.scrollRegions=t.scrollRegions||[],t.rememberedState=t.rememberedState||{},(c=c||d(t.url).href===window.location.href)?r.replaceState(t):r.pushState(t),r.swapComponent({component:e,page:t,preserveState:f}).then((function(){u||r.resetScrollPositions(),c||b(t)})))}))},r.pushState=function(t){this.page=t,window.history.pushState(t,"",t.url)},r.replaceState=function(t){this.page=t,window.history.replaceState(t,"",t.url)},r.handlePopstateEvent=function(t){var e=this;if(null!==t.state){var r=t.state,n=this.createVisitId();Promise.resolve(this.resolveComponent(r.component)).then((function(t){n===e.visitId&&(e.page=r,e.swapComponent({component:t,page:r,preserveState:!1}).then((function(){e.restoreScrollPositions(),b(r)})))}))}else{var o=d(this.page.url);o.hash=window.location.hash,this.replaceState(c({},this.page,{url:o.href})),this.resetScrollPositions()}},r.get=function(t,r,n){return void 0===r&&(r={}),void 0===n&&(n={}),this.visit(t,c({},n,{method:e.n$.GET,data:r}))},r.reload=function(t){return void 0===t&&(t={}),this.visit(window.location.href,c({},t,{preserveScroll:!0,preserveState:!0}))},r.replace=function(t,e){var r;return void 0===e&&(e={}),console.warn("Inertia.replace() has been deprecated and will be removed in a future release. Please use Inertia."+(null!=(r=e.method)?r:"get")+"() instead."),this.visit(t,c({preserveState:!0},e,{replace:!0}))},r.post=function(t,r,n){return void 0===r&&(r={}),void 0===n&&(n={}),this.visit(t,c({preserveState:!0},n,{method:e.n$.POST,data:r}))},r.put=function(t,r,n){return void 0===r&&(r={}),void 0===n&&(n={}),this.visit(t,c({preserveState:!0},n,{method:e.n$.PUT,data:r}))},r.patch=function(t,r,n){return void 0===r&&(r={}),void 0===n&&(n={}),this.visit(t,c({preserveState:!0},n,{method:e.n$.PATCH,data:r}))},r.delete=function(t,r){return void 0===r&&(r={}),this.visit(t,c({preserveState:!0},r,{method:e.n$.DELETE}))},r.remember=function(t,e){var r,n;void 0===e&&(e="default"),w||this.replaceState(c({},this.page,{rememberedState:c({},null==(r=this.page)?void 0:r.rememberedState,(n={},n[e]=t,n))}))},r.restore=function(t){var e,r;if(void 0===t&&(t="default"),!w)return null==(e=window.history.state)||null==(r=e.rememberedState)?void 0:r[t]},r.on=function(t,e){var r=function(t){var r=e(t);t.cancelable&&!t.defaultPrevented&&!1===r&&t.preventDefault()};return document.addEventListener("inertia:"+t,r),function(){return document.removeEventListener("inertia:"+t,r)}},t}(),_={buildDOMElement:function(t){var e=document.createElement("template");e.innerHTML=t;var r=e.content.firstChild;if(!t.startsWith("