@honed/action
Version:
Create server-driven actions for your Inertia.js application.
2 lines (1 loc) • 2.33 kB
JavaScript
(function(c,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue"),require("@inertiajs/vue3"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","@inertiajs/vue3","axios"],a):(c=typeof globalThis<"u"?globalThis:c||self,a(c["@honed/action"]={},c.Vue,c.Inertia,c.axios))})(this,function(c,a,b,y){"use strict";function s(e,f={},u={}){if(!e.href||!e.method)return!1;if(e.type==="inertia")e.method==="delete"?b.router.delete(e.href,u):b.router[e.method](e.href,f,u);else{const n=i=>{var r;return(r=u.onError)==null?void 0:r.call(u,i)};e.method==="get"?window.location.href=e.href:e.method==="delete"?y.delete(e.href).catch(n):y[e.method](e.href,f).catch(n)}return!0}function v(e,f={},u={}){return e.map(n=>({...n,execute:(i={},r={})=>s(n,{...u,...i},{...f,...r})}))}function w(e,f,u={}){if(!(e!=null&&e[f]))throw new Error("The batch must be provided with valid props and key.");const n=a.computed(()=>e[f]),i=a.computed(()=>v(n.value.inline)),r=a.computed(()=>v(n.value.bulk)),h=a.computed(()=>v(n.value.page));function o(d,t,l={}){return s(d,t,{...u,...l})}function m(d,t,l={}){return s(d,t,{...u,...l})}function x(d,t={},l={}){return s(d,t,{...u,...l})}return{inline:i,bulk:r,page:h,executeInline:o,executeBulk:m,executePage:x}}function E(){const e=a.ref({all:!1,only:new Set,except:new Set});function f(){e.value.all=!0,e.value.only.clear(),e.value.except.clear()}function u(){e.value.all=!1,e.value.only.clear(),e.value.except.clear()}function n(...t){t.forEach(l=>e.value.except.delete(l)),t.forEach(l=>e.value.only.add(l))}function i(...t){t.forEach(l=>e.value.except.add(l)),t.forEach(l=>e.value.only.delete(l))}function r(t,l){if(h(t)||l===!1)return i(t);if(!h(t)||l===!0)return n(t)}function h(t){return e.value.all?!e.value.except.has(t):e.value.only.has(t)}const o=a.computed(()=>e.value.all&&e.value.except.size===0),m=a.computed(()=>e.value.only.size>0||o.value);function x(t){return{"onUpdate:modelValue":l=>{l?n(t):i(t)},modelValue:h(t),value:t}}function d(){return{"onUpdate:modelValue":t=>{t?f():u()},modelValue:o.value}}return{allSelected:o,selection:e,hasSelected:m,selectAll:f,deselectAll:u,select:n,deselect:i,toggle:r,selected:h,bind:x,bindAll:d}}c.executables=v,c.execute=s,c.useBatch=w,c.useBulk=E,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});