@stonecrop/atable 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/atable.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, inject, mergeModels, mergeProps, nextTick, normalizeClass, normalizeProps, normalizeStyle, onMounted, onUnmounted, openBlock, reactive, ref, renderList, renderSlot, resolveDynamicComponent, toDisplayString, toValue, unref, useCssVars, useModel, useTemplateRef, vModelCheckbox, vModelSelect, vModelText, vShow, watch, withCtx, withDirectives, withModifiers } from "vue";
|
|
2
|
-
import { defaultKeypressHandlers, useKeyboardNav } from "@stonecrop/utilities";
|
|
2
|
+
import { defaultKeypressHandlers, fromISODate, useKeyboardNav } from "@stonecrop/utilities";
|
|
3
3
|
import { componentCategory, hasBadgeOptions, isBadgeDescriptor } from "@stonecrop/schema";
|
|
4
4
|
import { onClickOutside, useDebounceFn, useDraggable, useElementBounding, useMutationObserver, useResizeObserver } from "@vueuse/core";
|
|
5
5
|
import { defineStore } from "pinia";
|
|
6
|
+
import { Temporal } from "temporal-polyfill";
|
|
6
7
|
import { vOnClickOutside, vResizeObserver } from "@vueuse/components";
|
|
7
8
|
import './assets/index.css';//#region src/linkSearchableText.ts
|
|
8
9
|
/**
|
|
@@ -46,6 +47,7 @@ var CATEGORY_FILTER = {
|
|
|
46
47
|
boolean: "checkbox",
|
|
47
48
|
date: "date",
|
|
48
49
|
datetime: "dateRange",
|
|
50
|
+
duration: "text",
|
|
49
51
|
select: "select",
|
|
50
52
|
code: "text",
|
|
51
53
|
link: "text",
|
|
@@ -121,6 +123,19 @@ function isNodeOpen(rowIndex, treeDisplay) {
|
|
|
121
123
|
if (parentIndex < 0 || parentIndex >= treeDisplay.length) return false;
|
|
122
124
|
return (treeDisplay[parentIndex].childrenOpen || false) && isNodeOpen(parentIndex, treeDisplay);
|
|
123
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* The `YYYY-MM-DD` day a date cell shows as: a day column's day, a date-time's day in the user's zone,
|
|
128
|
+
* and for a column declaring no date component, the UTC day its value parses to. Undefined when the
|
|
129
|
+
* cell holds no date.
|
|
130
|
+
*/
|
|
131
|
+
function dayOfCell(cellValue, column) {
|
|
132
|
+
const category = componentCategory(column.component);
|
|
133
|
+
if (category === "date") return fromISODate(String(cellValue))?.toString();
|
|
134
|
+
const epochMilliseconds = new Date(String(cellValue)).getTime();
|
|
135
|
+
if (isNaN(epochMilliseconds)) return void 0;
|
|
136
|
+
const zone = category === "datetime" ? Temporal.Now.timeZoneId() : "UTC";
|
|
137
|
+
return Temporal.Instant.fromEpochMilliseconds(epochMilliseconds).toZonedDateTimeISO(zone).toPlainDate().toString();
|
|
138
|
+
}
|
|
124
139
|
function applyFilter(cellValue, filter, column) {
|
|
125
140
|
const filterType = resolveFilterType(column);
|
|
126
141
|
const value = filter.value;
|
|
@@ -136,28 +151,15 @@ function applyFilter(cellValue, filter, column) {
|
|
|
136
151
|
case "checkbox":
|
|
137
152
|
if (value === true) return !!cellValue;
|
|
138
153
|
return true;
|
|
139
|
-
case "date":
|
|
140
|
-
let cellDate;
|
|
141
|
-
if (typeof cellValue === "number") {
|
|
142
|
-
const originalDate = new Date(cellValue);
|
|
143
|
-
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
144
|
-
cellDate = new Date(currentYear, originalDate.getMonth(), originalDate.getDate());
|
|
145
|
-
} else cellDate = new Date(String(cellValue));
|
|
146
|
-
const filterDate = new Date(String(value));
|
|
147
|
-
return cellDate.toDateString() === filterDate.toDateString();
|
|
148
|
-
}
|
|
154
|
+
case "date": return dayOfCell(cellValue, column) === String(value);
|
|
149
155
|
case "dateRange": {
|
|
150
156
|
const startValue = filter.startValue;
|
|
151
157
|
const endValue = filter.endValue;
|
|
152
158
|
if (!startValue && !endValue) return true;
|
|
153
|
-
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
cellDateRange = new Date(currentYear, originalDate.getMonth(), originalDate.getDate());
|
|
158
|
-
} else cellDateRange = new Date(String(cellValue));
|
|
159
|
-
if (startValue && cellDateRange < new Date(String(startValue))) return false;
|
|
160
|
-
if (endValue && cellDateRange > new Date(String(endValue))) return false;
|
|
159
|
+
const cellDay = dayOfCell(cellValue, column);
|
|
160
|
+
if (cellDay === void 0) return false;
|
|
161
|
+
if (startValue && cellDay < String(startValue)) return false;
|
|
162
|
+
if (endValue && cellDay > String(endValue)) return false;
|
|
161
163
|
return true;
|
|
162
164
|
}
|
|
163
165
|
default: return true;
|
|
@@ -410,7 +412,7 @@ var createTableStore = (initData) => {
|
|
|
410
412
|
if (!format) {
|
|
411
413
|
const category = componentCategory(column.component);
|
|
412
414
|
if (category === "boolean") return value ? "✓" : "✗";
|
|
413
|
-
if (category === "date") return value != null ?
|
|
415
|
+
if (category === "date") return value != null ? fromISODate(String(value))?.toLocaleString() ?? "Invalid Date" : value;
|
|
414
416
|
if (category === "datetime") return value != null ? new Date(String(value)).toLocaleString() : value;
|
|
415
417
|
if (category === "quantity") return formatQuantity(value);
|
|
416
418
|
if (category === "currency") return formatCurrency(value);
|