UNPKG

@trail-ui/react

Version:
103 lines (101 loc) 2.99 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/editable-table/helpers.tsx var helpers_exports = {}; __export(helpers_exports, { areArraysSame: () => areArraysSame, dateSortingFn: () => dateSortingFn, multiSelectFilter: () => multiSelectFilter }); module.exports = __toCommonJS(helpers_exports); function multiSelectFilter(row, columnId, filterValue) { if (!Array.isArray(filterValue)) { return true; } const rowValue = row.getValue(columnId); return filterValue.includes(rowValue); } function dateSortingFn(rowA, rowB, columnId) { const dateStringA = rowA.getValue(columnId); const dateStringB = rowB.getValue(columnId); const parseCustomDate = (dateStr) => { if (!dateStr) { return new Date(Number.NaN); } const parts = dateStr.trim().split(" "); if (parts.length !== 3) { return new Date(Number.NaN); } const [day, month, year] = parts; const months = { Jan: "01", Feb: "02", Mar: "03", Apr: "04", May: "05", Jun: "06", Jul: "07", Aug: "08", Sep: "09", Oct: "10", Nov: "11", Dec: "12" }; const monthNum = months[month]; if (!monthNum) { return new Date(Number.NaN); } const isoDate = `${year}-${monthNum}-${day.padStart(2, "0")}`; return new Date(isoDate); }; const dateA = parseCustomDate(dateStringA); const dateB = parseCustomDate(dateStringB); if (Number.isNaN(dateA.getTime()) && Number.isNaN(dateB.getTime())) { return 0; } if (Number.isNaN(dateA.getTime())) { return 1; } if (Number.isNaN(dateB.getTime())) { return -1; } return dateA.getTime() - dateB.getTime(); } function areArraysSame(a, b) { if (a.length !== b.length) return false; const countMap = /* @__PURE__ */ new Map(); for (const value of a) { countMap.set(value, (countMap.get(value) || 0) + 1); } for (const value of b) { if (!countMap.has(value)) return false; countMap.set(value, countMap.get(value) - 1); if (countMap.get(value) < 0) return false; } return true; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { areArraysSame, dateSortingFn, multiSelectFilter });