@flavorly/vanilla-components-inertia
Version:
🤌 Inertia integration for @flavorly/vanilla-components
46 lines (44 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
module.exports = useInertiaDatatable;
var _vue = require("@inertiajs/vue3");
function useInertiaDatatable(configuration, options = {
actionsCallback: true
}) {
if (options.actionsCallback && configuration.actions?.length > 0) {
configuration.actions = configuration.actions.map(action => {
if (action.after?.inertia) {
action.after.callback = (action2, data, datatable) => {
const inertia = action2.after?.inertia;
if (inertia && inertia.reload) {
_vue.router.reload({
...inertia.options,
data: {
...(inertia.options?.data || {}),
datatable: {
[datatable.name]: data
}
}
});
}
if (inertia && !inertia.reload && action2.after?.inertia?.url) {
_vue.router.visit(inertia.url, {
...inertia.options,
data: {
...(inertia.options?.data || {}),
datatable: {
[datatable.name]: data
}
}
// data: inertia.options.data ? { ...inertia.options.data, ...data } : data,
});
}
};
}
return action;
});
}
return configuration;
}