UNPKG

@progress/kendo-vue-grid

Version:
337 lines (336 loc) 8.18 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2026 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { defineComponent as l, createVNode as d } from "vue"; import { provideLocalizationService as p } from "@progress/kendo-vue-intl"; import { ContextMenu as x } from "@progress/kendo-vue-layout"; import { sortDescSmallIcon as I, sortAscSmallIcon as f, fileExcelIcon as u, filePdfIcon as g, chevronUpIcon as h, chevronDownIcon as c, chevronDoubleUpIcon as C, chevronDoubleDownIcon as v, clipboardIcon as w, fileTxtIcon as S, pageHeaderSectionIcon as R, unpinIcon as i, pinBottomIcon as r, pinTopIcon as s, pinIcon as b, tableRowGroupsIcon as y, gridIcon as D, tableUnmergeIcon as E, tableBodyIcon as P, trashIcon as A, pencilIcon as T, plusIcon as B } from "@progress/kendo-svg-icons"; import { GridContextMenuItemNames as t } from "./enums.mjs"; const H = { [t.create]: { name: "create", text: "Add", icon: "plus", svgIcon: B, data: { action: "AddCommand" } }, [t.edit]: { name: "edit", text: "Edit", icon: "pencil", svgIcon: T, data: { action: "EditCommand" } }, [t.delete]: { name: "delete", text: "Delete", icon: "trash", svgIcon: A, data: { action: "DeleteCommand" } }, [t.select]: { name: "select", text: "Select", icon: "table-body", svgIcon: P, items: [{ name: "selectRow", text: "Row", icon: "table-row-groups", svgIcon: y, data: { action: "SelectRowCommand" } }, { name: "selectAllRows", text: "All rows", icon: "grid", svgIcon: D, data: { action: "SelectAllRowsCommand" } }, { name: "clearSelection", text: "Clear selection", icon: "table-unmerge", svgIcon: E, data: { action: "ClearSelectionCommand" } }] }, [t.pinRow]: { name: "pinRow", text: "Pin row", icon: "pin", svgIcon: b, items: [{ name: "pinTop", text: "Pin to Top", icon: "pin-top", svgIcon: s, data: { action: "PinTopCommand" } }, { name: "pinBottom", text: "Pin to Bottom", icon: "pin-bottom", svgIcon: r, data: { action: "PinBottomCommand" } }, { name: "unpin", text: "Unpin", icon: "unpin", svgIcon: i, data: { action: "UnpinCommand" } }] }, [t.pinTop]: { name: "pinTop", text: "Pin to Top", icon: "pin-top", svgIcon: s, data: { action: "PinTopCommand" } }, [t.pinBottom]: { name: "pinBottom", text: "Pin to Bottom", icon: "pin-bottom", svgIcon: r, data: { action: "PinBottomCommand" } }, [t.unpin]: { name: "unpin", text: "Unpin", icon: "unpin", svgIcon: i, data: { action: "UnpinCommand" } }, [t.copySelection]: { name: "copySelection", text: "Copy selection", icon: "page-header-section", svgIcon: R, data: { action: "CopySelectionCommand" }, options: "withHeaders" }, [t.copySelectionNoHeaders]: { name: "copySelectionNoHeaders", text: "Copy selection (No Headers)", icon: "file-txt", svgIcon: S, data: { action: "CopySelectionCommand" } }, [t.paste]: { name: "paste", text: "Paste (use CTRL/⌘ + V)", icon: "clipboard", svgIcon: w, data: { action: "PasteCommand" } }, [t.reorderRow]: { name: "reorderRow", text: "Reorder row", icon: "chevron-down", svgIcon: c, items: [{ name: "reorderRowUp", text: "Up", icon: "chevron-up", svgIcon: h, data: { action: "ReorderRowCommand" } }, { name: "reorderRowDown", text: "Down", icon: "chevron-down", svgIcon: c, data: { action: "ReorderRowCommand" } }, { name: "reorderRowTop", text: "Top", icon: "chevron-double-up", svgIcon: C, data: { action: "ReorderRowCommand" } }, { name: "reorderRowBottom", text: "Bottom", icon: "chevron-double-down", svgIcon: v, data: { action: "ReorderRowCommand" } }] }, [t.exportPDF]: { name: "exportPDF", text: "Export to PDF", icon: "file-pdf", svgIcon: g, data: { action: "ExportPDFCommand" } }, [t.exportExcel]: { name: "exportExcel", text: "Export to Excel", icon: "file-excel", svgIcon: u, items: [{ name: "exportToExcelAll", text: "All", data: { action: "ExportExcelCommand" } }, { name: "exportToExcelSelection", text: "Selection", data: { action: "ExportExcelCommand" }, options: "selection,withHeaders" }, { name: "exportToExcelSelectionNoHeaders", text: "Selection (No Headers)", data: { action: "ExportExcelCommand" }, options: "selection" }] }, [t.separator]: { name: "separator", separator: !0 }, [t.sortAsc]: { name: "sortAsc", text: "Sort Ascending", icon: "sort-asc-small", svgIcon: f, data: { action: "SortCommand" } }, [t.sortDesc]: { name: "sortDesc", text: "Sort Descending", icon: "sort-desc-small", svgIcon: I, data: { action: "SortCommand" } } }, z = (o) => { let e = []; return o.sortable && (e = e.concat([t.sortAsc, t.sortDesc])), o.pdf && (e.length && (e = e.concat([t.separator])), e = e.concat([t.exportPDF])), e; }, G = (o) => { let e = []; return o.clipboard && (e = e.concat([t.copySelection, t.copySelectionNoHeaders, t.paste])), o.editable && (e.length && (e = e.concat([t.separator])), e = e.concat([t.create, t.edit, t.delete])), o.selectable && (e.length && (e = e.concat([t.separator])), e = e.concat([t.select])), o.rowReorderable && (e.length && (e = e.concat([t.separator])), e = e.concat([t.reorderRow])), o.pdf && (e.length && (e = e.concat([t.separator])), e = e.concat([t.exportPDF])), o.pinnable && (e.length && (e = e.concat([t.separator])), e = e.concat([t.pinRow])), e; }, L = /* @__PURE__ */ l({ name: "GridContextMenu", props: { show: { type: Boolean, default: !1 }, offset: { type: Object, default: () => ({ left: 0, top: 0 }) }, dataItem: { type: Object, default: void 0 }, field: { type: String, default: void 0 }, items: { type: Array, default: void 0 } }, inject: { kendoLocalizationService: { default: null } }, emits: ["close", "select"], methods: { localizeItem(o, e) { const n = { ...o }; return n.text && n.name && (n.text = e.toLanguageString(`contextMenu.${n.name}`, n.text || "")), n.items && Array.isArray(n.items) && (n.items = n.items.map((a) => this.localizeItem(a, e))), n; }, menuItems() { if (this.$props.items) return this.$props.items.map((o) => typeof o == "string" ? { ...H[o] } : { ...o }); }, handleSelect(o) { this.$emit("select", { event: o, dataItem: this.$props.dataItem, field: this.$props.field }); }, handleClose() { this.$emit("close"); } }, render() { const o = p(this), e = this.menuItems(), n = e == null ? void 0 : e.map((m) => this.localizeItem(m, o)), a = !!(this.$props.show && (n != null && n.length)); return d(x, { show: a, offset: this.$props.offset, items: n, onClose: this.handleClose, onSelect: this.handleSelect }, null); } }); export { L as GridContextMenu, H as contextMenuItemsMap, G as getDefaultBodyContextMenuItems, z as getDefaultHeadContextMenuItems };