@dolusoft/query-table 3.9.0 → 3.10.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.
@@ -1261,12 +1261,19 @@ var reorder_handle_default = /* @__PURE__ */ defineComponent({
1261
1261
  * load-more). A subtable or a spanning cell would otherwise widen the
1262
1262
  * columns it spans with content that is not theirs.
1263
1263
  */
1264
- var notCounted = [
1265
- ":scope > thead > tr > th[data-field] > .qt-filter",
1264
+ var notCountedParts = [
1266
1265
  ":scope > thead > tr > th[data-field] > .qt-resize-handle",
1267
1266
  ":scope > tbody > tr:not([data-row-index])",
1268
1267
  ":scope > tfoot"
1269
- ].join(", ");
1268
+ ];
1269
+ var filterRow = ":scope > thead > tr > th[data-field] > .qt-filter";
1270
+ var notCounted = [filterRow, ...notCountedParts].join(", ");
1271
+ var notCountedWithFilters = notCountedParts.join(", ");
1272
+ /**
1273
+ * The room a text, number or date filter input keeps for its text when the
1274
+ * filter row counts (C-100): six characters of the input's own font.
1275
+ */
1276
+ var filterText = "6ch";
1270
1277
  /**
1271
1278
  * Sets inline declarations for one read and puts every `style` attribute
1272
1279
  * back exactly as it was, absent included, so the markup after the call is
@@ -1302,7 +1309,7 @@ var styleSwap = () => {
1302
1309
  * (C-101): it is laid out the same way, its `col` widths left out, and a
1303
1310
  * column takes the wider of its header cell and its body cells.
1304
1311
  */
1305
- var measureColumnWidths = (table, fields, body) => {
1312
+ var measureColumnWidths = (table, fields, body, options = {}) => {
1306
1313
  const widths = {};
1307
1314
  if (!table?.tHead) return widths;
1308
1315
  const wanted = fields ? new Set(fields) : null;
@@ -1313,7 +1320,8 @@ var measureColumnWidths = (table, fields, body) => {
1313
1320
  swap.set(table, "width", "max-content");
1314
1321
  swap.set(table, "min-width", "0");
1315
1322
  for (const th of headers) swap.set(th, "width", "auto");
1316
- for (const part of Array.from(table.querySelectorAll(notCounted))) swap.set(part, "display", "none");
1323
+ for (const part of Array.from(table.querySelectorAll(options.filters ? notCountedWithFilters : notCounted))) swap.set(part, "display", "none");
1324
+ if (options.filters) countFilters(table, swap);
1317
1325
  const split = body && body !== table ? body : null;
1318
1326
  if (split) {
1319
1327
  swap.set(split, "table-layout", "auto");
@@ -1323,18 +1331,109 @@ var measureColumnWidths = (table, fields, body) => {
1323
1331
  for (const part of Array.from(split.querySelectorAll(":scope > tbody > tr:not([data-row-index])"))) swap.set(part, "display", "none");
1324
1332
  }
1325
1333
  const firstRow = split?.querySelector(":scope > tbody > tr[data-row-index]");
1334
+ const measured = [];
1326
1335
  for (const th of headers) {
1327
1336
  const field = th.dataset.field;
1328
1337
  if (field === void 0 || wanted && !wanted.has(field)) continue;
1338
+ const own = th.getBoundingClientRect().width;
1339
+ if (own === 0) continue;
1329
1340
  const cell = firstRow?.querySelector(`:scope > td[data-field="${CSS.escape(field)}"]`);
1330
- const width = Math.max(th.getBoundingClientRect().width, cell?.getBoundingClientRect().width ?? 0);
1331
- if (width > 0) widths[field] = Math.ceil(width);
1341
+ measured.push([
1342
+ field,
1343
+ th,
1344
+ Math.max(own, cell?.getBoundingClientRect().width ?? 0)
1345
+ ]);
1332
1346
  }
1347
+ const floors = options.filters ? filterFloors(measured.map(([, th]) => th), swap) : null;
1348
+ for (const [field, th, width] of measured) widths[field] = Math.ceil(Math.max(width, floors?.get(th) ?? 0));
1333
1349
  } finally {
1334
1350
  swap.restore();
1335
1351
  }
1336
1352
  return widths;
1337
1353
  };
1354
+ /**
1355
+ * Takes the filter rows out of the read (C-100): out of the cell's flow
1356
+ * (`position: absolute`), so nothing in them widens the column by being
1357
+ * there, and no size container, which would switch the row to its narrow
1358
+ * form. Each control of the table stops growing and shrinking: a text or
1359
+ * number input six characters wide (padding and border on top), a select
1360
+ * and a date or time input as wide as they draw themselves, a filter button
1361
+ * at its own width, back in the row's flow when a skin's narrow form laid it
1362
+ * `absolute` over the input. A control `fixed` over the page (a panel)
1363
+ * stays out.
1364
+ */
1365
+ var countFilters = (table, swap) => {
1366
+ const rows = Array.from(table.querySelectorAll(filterRow));
1367
+ for (const row of rows) {
1368
+ swap.set(row, "position", "absolute");
1369
+ swap.set(row, "container-type", "normal");
1370
+ swap.set(row, "contain", "none");
1371
+ swap.set(row, "box-sizing", "content-box");
1372
+ for (const input of Array.from(row.querySelectorAll(":scope > .qt-filter-input"))) {
1373
+ swap.set(input, "flex", "none");
1374
+ swap.set(input, "min-width", "0");
1375
+ if (input instanceof HTMLInputElement && textTypes.has(input.type)) {
1376
+ swap.set(input, "box-sizing", "content-box");
1377
+ swap.set(input, "width", filterText);
1378
+ } else swap.set(input, "width", "auto");
1379
+ }
1380
+ for (const button of Array.from(row.querySelectorAll(":scope > .qt-filter-button"))) swap.set(button, "flex", "none");
1381
+ }
1382
+ for (const row of rows) for (const button of Array.from(row.querySelectorAll(":scope > .qt-filter-button"))) if (getComputedStyle(button).position === "absolute") swap.set(button, "position", "static");
1383
+ };
1384
+ /** The inputs that keep six characters of text; the others draw their own. */
1385
+ var textTypes = /* @__PURE__ */ new Set([
1386
+ "text",
1387
+ "number",
1388
+ "search"
1389
+ ]);
1390
+ var horizontal = (style) => (parseFloat(style.paddingLeft) || 0) + (parseFloat(style.paddingRight) || 0) + (parseFloat(style.borderLeftWidth) || 0) + (parseFloat(style.borderRightWidth) || 0);
1391
+ /** The table's own filter controls, the row's children, that take room. */
1392
+ var controlsOf = (row) => Array.from(row.querySelectorAll(":scope > :is(.qt-filter-input, .qt-filter-button)")).filter((control) => {
1393
+ const { position } = getComputedStyle(control);
1394
+ return position !== "fixed" && position !== "absolute";
1395
+ });
1396
+ /** The row's content width the probes draw it at: `0` and this. */
1397
+ var probe = 1e3;
1398
+ /**
1399
+ * The width each header cell needs for its filter controls, from the
1400
+ * controls alone: the row's width is never read, so slot content in it
1401
+ * cannot count, by its own width or by a width it took from the column. The
1402
+ * controls are drawn side by side in rows `0` and `probe` pixels wide, and
1403
+ * each width (a control, the gap) is taken as a fixed part plus a share of
1404
+ * the row, which is what a percentage padding is. The row then needs `R`
1405
+ * with `R = fixed + share * R`, the cell `R` plus the row's and the cell's
1406
+ * padding and border.
1407
+ */
1408
+ var filterFloors = (headers, swap) => {
1409
+ const rows = headers.flatMap((th) => {
1410
+ const row = th.querySelector(":scope > .qt-filter");
1411
+ const controls = row ? controlsOf(row) : [];
1412
+ return row && controls.length > 0 ? [{
1413
+ th,
1414
+ row,
1415
+ controls
1416
+ }] : [];
1417
+ });
1418
+ const read = (width) => {
1419
+ for (const { row } of rows) swap.set(row, "width", `${width}px`);
1420
+ return rows.map(({ row, controls }) => {
1421
+ const drawn = controls.map((control) => control.getBoundingClientRect().width).filter((each) => each > 0);
1422
+ const gap = parseFloat(getComputedStyle(row).columnGap) || 0;
1423
+ return drawn.length === 0 ? 0 : drawn.reduce((sum, each) => sum + each, 0) + gap * (drawn.length - 1);
1424
+ });
1425
+ };
1426
+ const atZero = read(0);
1427
+ const atProbe = read(probe);
1428
+ const floors = /* @__PURE__ */ new Map();
1429
+ rows.forEach(({ th, row }, index) => {
1430
+ const fixed = atZero[index];
1431
+ if (fixed === 0) return;
1432
+ const share = Math.min(.9, Math.max(0, (atProbe[index] - fixed) / probe));
1433
+ floors.set(th, fixed / (1 - share) + horizontal(getComputedStyle(row)) + horizontal(getComputedStyle(th)));
1434
+ });
1435
+ return floors;
1436
+ };
1338
1437
  //#endregion
1339
1438
  //#region src/resize/width-scale.ts
1340
1439
  var same = (width) => width;
@@ -1523,7 +1622,7 @@ var useColumnResize = (options) => {
1523
1622
  const scale = scaleOf(th, column);
1524
1623
  const from = scale.declared(drawn);
1525
1624
  const step = scale.declared(Math.round(drawn) + sign * (event.shiftKey ? 50 : 10));
1526
- const to = sign ? from + sign * Math.max(1, Math.abs(step - from)) : measureColumnWidths(th.closest("table"), [column.field], options.body())[column.field];
1625
+ const to = sign ? from + sign * Math.max(1, Math.abs(step - from)) : measureColumnWidths(th.closest("table"), [column.field], options.body(), { filters: true })[column.field];
1527
1626
  if (to !== void 0) commit(column, from, to);
1528
1627
  }
1529
1628
  };
@@ -2165,7 +2264,7 @@ var useAutoWidth = (options) => {
2165
2264
  result = cloneQuery(query);
2166
2265
  }
2167
2266
  if (options.rows().length === 0) return;
2168
- const measured = measureColumnWidths(table, columns.map((column) => column.field), options.body());
2267
+ const measured = measureColumnWidths(table, columns.map((column) => column.field), options.body(), { filters: true });
2169
2268
  if (Object.keys(measured).length === 0) {
2170
2269
  waiting = true;
2171
2270
  return;