UNPKG

@progress/kendo-vue-data-tools

Version:
117 lines (116 loc) 3.27 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { defineComponent as v, createVNode as n, inject as C } from "vue"; import { ColumnMenuItem as a } from "./ColumnMenuItem.mjs"; import { ColumnMenuItemGroup as D } from "./ColumnMenuItemGroup.mjs"; import { normalize as k } from "../interfaces/SortSettings.mjs"; import { provideLocalizationService as I } from "@progress/kendo-vue-intl"; import { columnMenuSortAscending as d, messages as m, columnMenuSortDescending as u } from "../messages/main.mjs"; import { hasListener as L } from "@progress/kendo-vue-common"; import { sortAscSmallIcon as M, sortDescSmallIcon as z } from "@progress/kendo-svg-icons"; const f = "asc", p = "desc", A = { true: { asc: { asc: "", desc: "desc" }, desc: { asc: "asc", desc: "" }, "": { asc: "asc", desc: "desc" } }, false: { asc: { asc: "asc", desc: "desc" }, desc: { asc: "asc", desc: "desc" }, "": { asc: "asc", desc: "desc" } } }, $ = (e, o) => o ? o.findIndex((t) => t.field === e) : -1, b = (e, o) => !!(o && e > -1 && o[e].dir === f), j = (e, o) => !!(o && e > -1 && o[e].dir === p), B = /* @__PURE__ */ v({ props: { sortable: [Boolean, Object], sort: { type: Array }, column: Object, onSortchange: Function, onClosemenu: Function }, inject: { kendoLocalizationService: { default: null } }, methods: { onAscClick(e) { this.onSort(e, f), this.$emit("closemenu"); }, onDescClick(e) { this.onSort(e, p), this.$emit("closemenu"); }, onSort(e, o) { if (e.preventDefault(), !L.call(this, "sortchange")) return; const { column: t, sortable: s, sort: S } = this.$props, { allowUnsort: h, mode: g } = k(s || !1, !1), i = (S || []).filter((c) => c.field === t.field)[0], r = A[h][i && i.dir || ""][o], l = g === "single" ? [] : (this.$props.sort || []).filter((c) => c.field !== t.field); r !== "" && t.field && l.push({ field: t.field, dir: r }), this.$emit("sortchange", l, { event: e, field: this.$props.column.field }); } }, setup() { return { kendoLocalizationService: C("kendoLocalizationService", {}) }; }, render() { const { sort: e, column: o } = this.$props, t = $(o.field, e), s = I(this); return n(D, null, { default: () => [n(a, { title: s.toLanguageString(d, m[d]), icon: "sort-asc-small", svgIcon: M, selected: b(t, e), onMenuitemclick: this.onAscClick }, null), n(a, { title: s.toLanguageString(u, m[u]), icon: "sort-desc-small", svgIcon: z, selected: j(t, e), onMenuitemclick: this.onDescClick }, null)] }); } }); export { B as ColumnMenuSort };