@dolusoft/query-table 3.5.1 → 3.6.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/query-table.js
CHANGED
|
@@ -1187,6 +1187,76 @@ var reorder_handle_default = /* @__PURE__ */ defineComponent({
|
|
|
1187
1187
|
}
|
|
1188
1188
|
});
|
|
1189
1189
|
//#endregion
|
|
1190
|
+
//#region src/resize/measure-widths.ts
|
|
1191
|
+
/**
|
|
1192
|
+
* What must not count, inside the table: the filter row and the resize handle
|
|
1193
|
+
* of a header cell (C-50 counts the label only), the footer, and every body
|
|
1194
|
+
* row that is not a data row (subtable, virtual spacer, loading, empty,
|
|
1195
|
+
* load-more). A subtable or a spanning cell would otherwise widen the
|
|
1196
|
+
* columns it spans with content that is not theirs.
|
|
1197
|
+
*/
|
|
1198
|
+
var notCounted = [
|
|
1199
|
+
":scope > thead > tr > th[data-field] > .qt-filter",
|
|
1200
|
+
":scope > thead > tr > th[data-field] > .qt-resize-handle",
|
|
1201
|
+
":scope > tbody > tr:not([data-row-index])",
|
|
1202
|
+
":scope > tfoot"
|
|
1203
|
+
].join(", ");
|
|
1204
|
+
/**
|
|
1205
|
+
* Sets inline declarations for one read and puts every `style` attribute
|
|
1206
|
+
* back exactly as it was, absent included, so the markup after the call is
|
|
1207
|
+
* the markup before it (C-31). `!important` so a consumer's `!important`
|
|
1208
|
+
* rule cannot keep the fixed layout during the read.
|
|
1209
|
+
*/
|
|
1210
|
+
var styleSwap = () => {
|
|
1211
|
+
const saved = /* @__PURE__ */ new Map();
|
|
1212
|
+
return {
|
|
1213
|
+
set(element, property, value) {
|
|
1214
|
+
if (!saved.has(element)) saved.set(element, element.getAttribute("style"));
|
|
1215
|
+
element.style.setProperty(property, value, "important");
|
|
1216
|
+
},
|
|
1217
|
+
restore() {
|
|
1218
|
+
for (const [element, style] of saved) if (style === null) {
|
|
1219
|
+
element.getAttribute("style");
|
|
1220
|
+
element.removeAttribute("style");
|
|
1221
|
+
} else element.setAttribute("style", style);
|
|
1222
|
+
saved.clear();
|
|
1223
|
+
}
|
|
1224
|
+
};
|
|
1225
|
+
};
|
|
1226
|
+
/**
|
|
1227
|
+
* The max-content width of each drawn column, by `field`: header label and
|
|
1228
|
+
* the cells of the drawn data rows, padding and border included, in whole
|
|
1229
|
+
* pixels rounded up. The browser lays the table out once with its automatic
|
|
1230
|
+
* layout and no widths, the parts that do not count taken out, and every
|
|
1231
|
+
* style is put back before the function returns: nothing is painted in
|
|
1232
|
+
* between, and slot content that draws a block or a flex box counts with the
|
|
1233
|
+
* width its content needs, not the width its cell gives it. Only `fields`
|
|
1234
|
+
* when given; a column with no box (the table not displayed) is left out.
|
|
1235
|
+
*/
|
|
1236
|
+
var measureColumnWidths = (table, fields) => {
|
|
1237
|
+
const widths = {};
|
|
1238
|
+
if (!table?.tHead) return widths;
|
|
1239
|
+
const wanted = fields ? new Set(fields) : null;
|
|
1240
|
+
const headers = Array.from(table.querySelectorAll(":scope > thead > tr > th[data-field]"));
|
|
1241
|
+
const swap = styleSwap();
|
|
1242
|
+
try {
|
|
1243
|
+
swap.set(table, "table-layout", "auto");
|
|
1244
|
+
swap.set(table, "width", "max-content");
|
|
1245
|
+
swap.set(table, "min-width", "0");
|
|
1246
|
+
for (const th of headers) swap.set(th, "width", "auto");
|
|
1247
|
+
for (const part of Array.from(table.querySelectorAll(notCounted))) swap.set(part, "display", "none");
|
|
1248
|
+
for (const th of headers) {
|
|
1249
|
+
const field = th.dataset.field;
|
|
1250
|
+
if (field === void 0 || wanted && !wanted.has(field)) continue;
|
|
1251
|
+
const width = th.getBoundingClientRect().width;
|
|
1252
|
+
if (width > 0) widths[field] = Math.ceil(width);
|
|
1253
|
+
}
|
|
1254
|
+
} finally {
|
|
1255
|
+
swap.restore();
|
|
1256
|
+
}
|
|
1257
|
+
return widths;
|
|
1258
|
+
};
|
|
1259
|
+
//#endregion
|
|
1190
1260
|
//#region src/resize/use-column-resize.ts
|
|
1191
1261
|
/** Default `Column.minWidth`, in pixels. */
|
|
1192
1262
|
var defaultMinWidth = 40;
|
|
@@ -1207,29 +1277,6 @@ var maxWidthOf = (column) => {
|
|
|
1207
1277
|
return max === void 0 ? void 0 : Math.max(max, minWidthOf(column));
|
|
1208
1278
|
};
|
|
1209
1279
|
var clampWidth = (column, width) => Math.round(Math.min(maxWidthOf(column) ?? Infinity, Math.max(minWidthOf(column), width)));
|
|
1210
|
-
/** Width of the content of a cell up to `until` (exclusive), padding and border included. */
|
|
1211
|
-
var contentWidth = (cell, until) => {
|
|
1212
|
-
const range = document.createRange();
|
|
1213
|
-
range.selectNodeContents(cell);
|
|
1214
|
-
if (until) range.setEndBefore(until);
|
|
1215
|
-
const style = getComputedStyle(cell);
|
|
1216
|
-
return [
|
|
1217
|
-
style.paddingLeft,
|
|
1218
|
-
style.paddingRight,
|
|
1219
|
-
style.borderLeftWidth,
|
|
1220
|
-
style.borderRightWidth
|
|
1221
|
-
].reduce((sum, value) => sum + (parseFloat(value) || 0), range.getBoundingClientRect().width);
|
|
1222
|
-
};
|
|
1223
|
-
/**
|
|
1224
|
-
* The widest rendered content of a column: the header label (the part before
|
|
1225
|
-
* the filter row and the handle) and the column's cells in this table's own
|
|
1226
|
-
* body rows. Only the rows given are measured (C-50).
|
|
1227
|
-
*/
|
|
1228
|
-
var autofitWidth = (th, field) => {
|
|
1229
|
-
let widest = contentWidth(th, th.querySelector(":scope > .qt-filter, :scope > .qt-resize-handle"));
|
|
1230
|
-
for (const cell of th.closest("table")?.tBodies[0]?.querySelectorAll(`:scope > tr[data-row-index] > td[data-field="${CSS.escape(field)}"]`) ?? []) widest = Math.max(widest, contentWidth(cell));
|
|
1231
|
-
return Math.ceil(widest);
|
|
1232
|
-
};
|
|
1233
1280
|
var cellOf = (event) => event.currentTarget.closest("th");
|
|
1234
1281
|
/**
|
|
1235
1282
|
* Which edge of the column the handle stands for: `1` for the right edge,
|
|
@@ -1316,7 +1363,8 @@ var useColumnResize = (options) => {
|
|
|
1316
1363
|
if (th && (sign || key === "Enter" || event.type === "dblclick")) {
|
|
1317
1364
|
event.preventDefault();
|
|
1318
1365
|
const from = th.getBoundingClientRect().width;
|
|
1319
|
-
|
|
1366
|
+
const to = sign ? Math.round(from) + sign * (event.shiftKey ? 50 : 10) : measureColumnWidths(th.closest("table"), [column.field])[column.field];
|
|
1367
|
+
if (to !== void 0) commit(column, from, to);
|
|
1320
1368
|
}
|
|
1321
1369
|
};
|
|
1322
1370
|
/**
|
|
@@ -3269,7 +3317,8 @@ var query_table_default = /* @__PURE__ */ defineComponent({
|
|
|
3269
3317
|
filters.flushAll();
|
|
3270
3318
|
},
|
|
3271
3319
|
scrollToIndex: rowWindow.scrollToIndex,
|
|
3272
|
-
loadMore: infinite.loadMore
|
|
3320
|
+
loadMore: infinite.loadMore,
|
|
3321
|
+
measureColumnWidths: (fields) => measureColumnWidths(tableEl.value, fields)
|
|
3273
3322
|
});
|
|
3274
3323
|
return (_ctx, _cache) => {
|
|
3275
3324
|
return openBlock(), createElementBlock("div", {
|