@dolusoft/query-table 3.12.0 → 3.14.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.
@@ -1,5 +1,5 @@
1
1
  import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createSlots, createStaticVNode, createTextVNode, createVNode, defineComponent, effectScope, getCurrentInstance, getCurrentScope, guardReactiveProps, h, inject, mergeProps, nextTick, normalizeProps, normalizeStyle, onActivated, onBeforeUnmount, onBeforeUpdate, onDeactivated, onMounted, onScopeDispose, openBlock, provide, renderList, renderSlot, shallowRef, toDisplayString, toHandlers, toValue, unref, useSlots, watch, watchEffect, withCtx, withKeys, withModifiers } from "vue";
2
- import { cloneQuery, columnTypeOf, columnTypeOf as columnTypeOf$1, conditionLabel, conditionOptions, isCursorQuery, parseFilterInput as parseFilterInput$1, rulesOf, sameQuery, searchOf } from "@dolusoft/query-protocol";
2
+ import { cloneQuery, columnTypeOf, columnTypeOf as columnTypeOf$1, conditionArity, conditionLabel, conditionOptions, isCursorQuery, parseFilterInput as parseFilterInput$1, rulesOf, sameQuery, searchOf } from "@dolusoft/query-protocol";
3
3
  import { createRowChangeTracker } from "@dolusoft/query-table-core/row-changes";
4
4
  import { dispose, filterInputFeature, projectServerQuery, serverQueryFeature } from "@dolusoft/query-table-core";
5
5
  import { columnFilteringFeature, columnOrderingFeature, columnPinningFeature, columnVisibilityFeature, functionalUpdate, globalFilteringFeature, rowExpandingFeature, rowPaginationFeature, rowPinningFeature, rowSelectionFeature, rowSortingFeature, tableFeatures, useTable } from "@tanstack/vue-table";
@@ -255,6 +255,8 @@ var defaultLabels = {
255
255
  expandRow: "Expand row",
256
256
  openRightPanel: "Open right panel",
257
257
  filterInput: (column) => `Filter ${column}`,
258
+ filterInputFrom: (column) => `Filter ${column} from`,
259
+ filterInputTo: (column) => `Filter ${column} to`,
258
260
  filterOptions: (column) => `Filter options for ${column}`,
259
261
  resizeColumn: (column) => `Resize ${column}`,
260
262
  moveColumn: (column) => `Move ${column}`,
@@ -1438,29 +1440,40 @@ var useFilterTrigger = (options) => defineComponent({
1438
1440
  //#endregion
1439
1441
  //#region src/parts/filter-cell.vue?vue&type=script&setup=true&lang.ts
1440
1442
  var _hoisted_1$6 = { class: "qt-filter" };
1441
- var _hoisted_2$3 = ["aria-label", "value"];
1442
- var _hoisted_3$3 = [
1443
+ var _hoisted_2$3 = [
1443
1444
  "type",
1444
1445
  "aria-label",
1445
1446
  "value",
1446
- "readonly"
1447
+ "onInput"
1448
+ ];
1449
+ var _hoisted_3$3 = [
1450
+ "aria-label",
1451
+ "value",
1452
+ "readonly",
1453
+ "aria-invalid"
1447
1454
  ];
1448
1455
  var _hoisted_4$3 = [
1456
+ "aria-label",
1457
+ "value",
1458
+ "readonly",
1459
+ "aria-invalid"
1460
+ ];
1461
+ var _hoisted_5$1 = [
1449
1462
  "aria-label",
1450
1463
  "value",
1451
1464
  "disabled"
1452
1465
  ];
1453
- var _hoisted_5$1 = { value: "" };
1454
- var _hoisted_6$1 = { value: "true" };
1455
- var _hoisted_7$1 = { value: "false" };
1456
- var _hoisted_8$1 = [
1466
+ var _hoisted_6$1 = { value: "" };
1467
+ var _hoisted_7$1 = { value: "true" };
1468
+ var _hoisted_8$1 = { value: "false" };
1469
+ var _hoisted_9 = [
1457
1470
  "type",
1458
1471
  "aria-label",
1459
1472
  "value",
1460
1473
  "readonly"
1461
1474
  ];
1462
- var _hoisted_9 = {
1463
- key: 5,
1475
+ var _hoisted_10 = {
1476
+ key: 7,
1464
1477
  class: "qt-filter-condition"
1465
1478
  };
1466
1479
  //#endregion
@@ -1492,6 +1505,32 @@ var filter_cell_default = /* @__PURE__ */ defineComponent({
1492
1505
  const count = filters.multiOf(props.column.field);
1493
1506
  return count > 0 ? `(${count})` : filters.draftOf(props.column.field).text;
1494
1507
  };
1508
+ const draft = () => filters.draftOf(props.column.field);
1509
+ const isMulti = () => filters.multiOf(props.column.field) > 0;
1510
+ const isInvalid = () => !isFiltered() && !isMulti() && draft().text.trim() !== "" && filters.labelOf(props.column.field)?.count === 0;
1511
+ const ordered = [
1512
+ "number",
1513
+ "integer",
1514
+ "date",
1515
+ "datetime"
1516
+ ];
1517
+ const isDated = () => props.type === "date" || props.type === "datetime";
1518
+ const hidesInput = () => {
1519
+ const { condition } = draft();
1520
+ return !isMulti() && props.type !== "bool" && condition !== null && conditionArity(condition) === 0;
1521
+ };
1522
+ const isRange = () => !isMulti() && draft().condition === "Between" && ordered.includes(props.type);
1523
+ const bounds = ["lower", "upper"];
1524
+ const boundText = (bound) => bound === "upper" ? draft().text2 ?? "" : draft().text;
1525
+ const boundName = (bound) => {
1526
+ const name = columnName(props.column);
1527
+ return bound === "upper" ? labels().filterInputTo(name) : labels().filterInputFrom(name);
1528
+ };
1529
+ const takes = (condition) => condition === "Between" ? ordered.includes(props.type) : conditionArity(condition) === 0 || conditionOptions[props.type].some((option) => option.value === condition);
1530
+ const offered = () => {
1531
+ const own = props.column.filterConditions;
1532
+ return own ? [...new Set(own)].filter(takes) : conditionOptions[props.type].map(({ value }) => value);
1533
+ };
1495
1534
  const currentCondition = () => rulesOf(props.query.filters, props.column.field)[0]?.condition ?? filters.draftOf(props.column.field).condition;
1496
1535
  const menuProps = () => {
1497
1536
  const { column } = props;
@@ -1499,7 +1538,7 @@ var filter_cell_default = /* @__PURE__ */ defineComponent({
1499
1538
  column,
1500
1539
  rules: rulesOf(props.query.filters, column.field),
1501
1540
  condition: currentCondition(),
1502
- conditions: conditionOptions[props.type].map(({ value }) => ({
1541
+ conditions: offered().map((value) => ({
1503
1542
  value,
1504
1543
  label: labels().filterCondition(value, props.type)
1505
1544
  })),
@@ -1512,10 +1551,11 @@ var filter_cell_default = /* @__PURE__ */ defineComponent({
1512
1551
  control: layout.controlOf(column.field)
1513
1552
  };
1514
1553
  };
1515
- const datetimeProps = () => ({
1554
+ const datetimeProps = (bound = null) => ({
1516
1555
  column: props.column,
1517
- value: filters.draftOf(props.column.field).text,
1518
- updateValue: (value) => filters.setInput(props.column.field, value)
1556
+ value: bound ? boundText(bound) : draft().text,
1557
+ updateValue: (value) => filters.setInput(props.column.field, value, bound ?? void 0),
1558
+ bound
1519
1559
  });
1520
1560
  const inputValue = (event) => event.target.value;
1521
1561
  const pick = (event) => {
@@ -1524,46 +1564,59 @@ var filter_cell_default = /* @__PURE__ */ defineComponent({
1524
1564
  };
1525
1565
  return (_ctx, _cache) => {
1526
1566
  return openBlock(), createElementBlock("div", _hoisted_1$6, [
1527
- __props.type === "string" ? (openBlock(), createElementBlock("input", {
1528
- key: 0,
1567
+ isRange() ? (openBlock(), createElementBlock(Fragment, { key: 0 }, renderList(bounds, (bound) => {
1568
+ return openBlock(), createElementBlock(Fragment, { key: bound }, [isDated() && _ctx.$slots["filter-datetime"] ? renderSlot(_ctx.$slots, "filter-datetime", mergeProps({ ref_for: true }, datetimeProps(bound)), void 0, void 0, 0) : (openBlock(), createElementBlock("input", {
1569
+ key: 1,
1570
+ type: isDated() ? "date" : "number",
1571
+ class: "qt-filter-input",
1572
+ "aria-label": boundName(bound),
1573
+ value: boundText(bound),
1574
+ onInput: ($event) => unref(filters).setInput(__props.column.field, inputValue($event), bound),
1575
+ onKeydown: _cache[0] || (_cache[0] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
1576
+ }, null, 40, _hoisted_2$3))], 64);
1577
+ }), 64)) : hidesInput() ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [], 64)) : __props.type === "string" ? (openBlock(), createElementBlock("input", {
1578
+ key: 2,
1529
1579
  type: "text",
1530
1580
  class: "qt-filter-input",
1531
1581
  "aria-label": inputName(),
1532
- value: unref(filters).draftOf(__props.column.field).text,
1533
- onInput: _cache[0] || (_cache[0] = ($event) => unref(filters).setInput(__props.column.field, inputValue($event))),
1534
- onKeydown: _cache[1] || (_cache[1] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
1535
- }, null, 40, _hoisted_2$3)) : __props.type === "number" || __props.type === "integer" ? (openBlock(), createElementBlock("input", {
1536
- key: 1,
1537
- type: unref(filters).multiOf(__props.column.field) ? "text" : "number",
1582
+ value: inputText(),
1583
+ readonly: isMulti(),
1584
+ "aria-invalid": isInvalid() || void 0,
1585
+ onInput: _cache[1] || (_cache[1] = ($event) => unref(filters).setInput(__props.column.field, inputValue($event))),
1586
+ onKeydown: _cache[2] || (_cache[2] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
1587
+ }, null, 40, _hoisted_3$3)) : __props.type === "number" || __props.type === "integer" ? (openBlock(), createElementBlock("input", {
1588
+ key: 3,
1589
+ type: "text",
1538
1590
  class: "qt-filter-input",
1539
1591
  "aria-label": inputName(),
1540
1592
  value: inputText(),
1541
- readonly: unref(filters).multiOf(__props.column.field) > 0,
1542
- onInput: _cache[2] || (_cache[2] = ($event) => unref(filters).setInput(__props.column.field, inputValue($event))),
1543
- onKeydown: _cache[3] || (_cache[3] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
1544
- }, null, 40, _hoisted_3$3)) : __props.type === "bool" ? (openBlock(), createElementBlock("select", {
1545
- key: 2,
1593
+ readonly: isMulti(),
1594
+ "aria-invalid": isInvalid() || void 0,
1595
+ onInput: _cache[3] || (_cache[3] = ($event) => unref(filters).setInput(__props.column.field, inputValue($event))),
1596
+ onKeydown: _cache[4] || (_cache[4] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
1597
+ }, null, 40, _hoisted_4$3)) : __props.type === "bool" ? (openBlock(), createElementBlock("select", {
1598
+ key: 4,
1546
1599
  class: "qt-filter-input",
1547
1600
  "aria-label": inputName(),
1548
1601
  value: unref(filters).draftOf(__props.column.field).text,
1549
1602
  disabled: unref(filters).multiOf(__props.column.field) > 0,
1550
- onChange: _cache[4] || (_cache[4] = ($event) => pick($event))
1603
+ onChange: _cache[5] || (_cache[5] = ($event) => pick($event))
1551
1604
  }, [
1552
- createElementVNode("option", _hoisted_5$1, toDisplayString(unref(labels)().boolAll), 1),
1553
- createElementVNode("option", _hoisted_6$1, toDisplayString(unref(labels)().boolTrue), 1),
1554
- createElementVNode("option", _hoisted_7$1, toDisplayString(unref(labels)().boolFalse), 1)
1555
- ], 40, _hoisted_4$3)) : (openBlock(), createElementBlock(Fragment, { key: 3 }, [_ctx.$slots["filter-datetime"] ? renderSlot(_ctx.$slots, "filter-datetime", normalizeProps(guardReactiveProps(datetimeProps())), void 0, void 0, 0) : (openBlock(), createElementBlock("input", {
1605
+ createElementVNode("option", _hoisted_6$1, toDisplayString(unref(labels)().boolAll), 1),
1606
+ createElementVNode("option", _hoisted_7$1, toDisplayString(unref(labels)().boolTrue), 1),
1607
+ createElementVNode("option", _hoisted_8$1, toDisplayString(unref(labels)().boolFalse), 1)
1608
+ ], 40, _hoisted_5$1)) : (openBlock(), createElementBlock(Fragment, { key: 5 }, [_ctx.$slots["filter-datetime"] ? renderSlot(_ctx.$slots, "filter-datetime", normalizeProps(guardReactiveProps(datetimeProps())), void 0, void 0, 0) : (openBlock(), createElementBlock("input", {
1556
1609
  key: 1,
1557
1610
  type: unref(filters).multiOf(__props.column.field) ? "text" : "date",
1558
1611
  class: "qt-filter-input",
1559
1612
  "aria-label": inputName(),
1560
1613
  value: inputText(),
1561
1614
  readonly: unref(filters).multiOf(__props.column.field) > 0,
1562
- onInput: _cache[5] || (_cache[5] = ($event) => unref(filters).setInput(__props.column.field, inputValue($event))),
1563
- onKeydown: _cache[6] || (_cache[6] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
1564
- }, null, 40, _hoisted_8$1))], 64)),
1565
- __props.type !== "bool" ? renderSlot(_ctx.$slots, "filter-menu", normalizeProps(guardReactiveProps(menuProps())), void 0, void 0, 4) : createCommentVNode("", true),
1566
- labelOf() ? (openBlock(), createElementBlock("small", _hoisted_9, toDisplayString(labelOf()), 1)) : createCommentVNode("", true)
1615
+ onInput: _cache[6] || (_cache[6] = ($event) => unref(filters).setInput(__props.column.field, inputValue($event))),
1616
+ onKeydown: _cache[7] || (_cache[7] = withKeys(($event) => unref(filters).apply(__props.column.field), ["enter"]))
1617
+ }, null, 40, _hoisted_9))], 64)),
1618
+ __props.type !== "bool" ? renderSlot(_ctx.$slots, "filter-menu", normalizeProps(guardReactiveProps(menuProps())), void 0, void 0, 6) : createCommentVNode("", true),
1619
+ labelOf() ? (openBlock(), createElementBlock("small", _hoisted_10, toDisplayString(labelOf()), 1)) : createCommentVNode("", true)
1567
1620
  ]);
1568
1621
  };
1569
1622
  }
@@ -3030,7 +3083,7 @@ function useQueryTable(options) {
3030
3083
  const draftOf = (field) => columnById(field)?.getFilterInput() ?? blank;
3031
3084
  const filters = {
3032
3085
  draftOf,
3033
- setInput: (field, text) => columnById(field)?.setFilterInput(text),
3086
+ setInput: (field, text, bound) => columnById(field)?.setFilterInput(text, bound),
3034
3087
  apply: (field) => columnById(field)?.applyFilterInput(),
3035
3088
  flushAll: () => table.flushPendingFilters(),
3036
3089
  setCondition: (field, condition) => columnById(field)?.setFilterCondition(condition),
@@ -4697,9 +4750,10 @@ var query_table_default = /* @__PURE__ */ defineComponent({
4697
4750
  *
4698
4751
  * - `string`: operator shortcuts (`*a*`, `a*`, `*a`, `!a`, `!*a*`, `a,b`);
4699
4752
  * a segment without an operator uses `condition`.
4700
- * - `number`: one rule with a number value; text that is not a finite number
4701
- * gives `[]`.
4702
- * - `integer`: the same, but only a whole number in the safe range; `2.5`
4753
+ * - `number`: one rule per comma-separated number value; a value after `!`
4754
+ * is `NotEqual` (`80,443`, `!80,!443`). A value that is not a finite
4755
+ * number, or a list that mixes `!` and plain values, gives `[]`.
4756
+ * - `integer`: the same, but only whole numbers in the safe range; `2.5`
4703
4757
  * and `9007199254740993` give `[]`.
4704
4758
  * - `bool`: `'true'` or `'false'` gives one rule with a boolean value;
4705
4759
  * anything else gives `[]`.