@itrocks/list 0.28.2 → 0.29.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/README.md CHANGED
@@ -31,7 +31,7 @@ HTML rendering provides columns, filters, ordered sorting and session preference
31
31
  business objects for API consumers. See the public methods below for their shared contracts.
32
32
 
33
33
  Column filter values use the same text highlight as the toolbar summary.
34
- After applying column filters, the toolbar shows a decorative filter icon and a read-only summary.
34
+ When a filter is active, the toolbar shows the read-only summary beside a button that focuses the first column filter.
35
35
  The summary uses unique single-word column labels when available.
36
36
  Applying a search from a column filter returns focus to that field and selects its full value.
37
37
  When the toolbar runs out of space, the filter and add-column button move to a second row.
@@ -111,20 +111,23 @@ HTML list filters interpret the first hyphen as an interval separator. Spaces ar
111
111
  - `2000 - 2010` uses inclusive `between(2000, 2010)`.
112
112
  - `-2010` means less than or equal to 2010.
113
113
  - `2000-` means greater than or equal to 2000.
114
- - A hyphen with neither bound applies no criterion.
115
-
116
- Leading `>`, `>=`, `<`, `<=`, `<>`, `!=` and `!` apply the corresponding comparison.
117
- The prefixes `<>`, `!=` and `!` mean not equal; the equals sign after `!` is optional.
118
- With `*` or `?` in their operand, these three prefixes request `NOT LIKE` instead, using the same wildcard conversion.
119
- A leading `=` requests exact equality, including an empty string. Spaces around explicit comparison operands are
120
- ignored.
114
+ - A lone hyphen matches the exact text `-` in a text column.
115
+
116
+ Leading `>`, `>=`, `<` and `<=` apply the corresponding comparison. A leading `=` compares the whole value.
117
+ On text, `!=`, `<>` and `≠` compare the whole value for inequality. Any wildcard characters in their operand are
118
+ literal. For example, `<>%Alien%` compares against the literal value `%Alien%`.
119
+ The `!` prefix excludes a text prefix or an explicit pattern. `!Alien` produces `NOT LIKE 'Alien%'` and `!*Alien*`
120
+ produces `NOT LIKE '%Alien%'`. A bare `=` finds the empty string, while `!` and `!=` find text different from the empty
121
+ string. Spaces around explicit comparison operands are ignored.
121
122
  Explicit operators take precedence over interval syntax, so `>=-10` compares with negative ten and `=A-B` matches `A-B`.
122
123
 
123
- Without an explicit comparison operator, `*` and `?` request `LIKE` for any property type, replacing all `*` with `%`
124
- and all `?` with `_`. The pattern is used as supplied without an extra trailing wildcard. Wildcards take precedence
125
- over interval syntax, so `2000-20??` becomes the pattern `2000-20__`.
124
+ Without a comparison operator, any of `*`, `%`, `?` and `_` selects `LIKE`. Date patterns follow the date rules below.
125
+ `*` and `%` stand for zero or more characters. `?` and `_` stand for a single character.
126
+ The explicit pattern supplies its own wildcards and takes precedence over interval syntax.
127
+ For example, `2000-20??` and `2000-20__` both produce the pattern `2000-20__`.
126
128
 
127
- `empty` is an alias for `!?*`; `!empty`, `!=empty` and `<>empty` mean `?*` (a non-empty value).
129
+ On text, `empty` finds the empty string and `!empty` finds non-empty values. On a numeric field or a single object
130
+ reference, they use `IS NULL` and `IS NOT NULL` respectively.
128
131
  The alias accepts the current language's translation through `trReverse()`, for example `vide` and `!vide` in French.
129
132
  Alias matching ignores case and surrounding spaces. Use `=empty` or `=vide` to match the literal word.
130
133
  For dates, these aliases use the existing empty (`!?`) and non-empty (`?`) date criteria.
@@ -193,13 +196,14 @@ Calendar periods include their full final day. Explicit comparisons use the corr
193
196
  period: `>2020` starts after 2020, and `<=2020` includes all of 2020. Not-equal comparisons exclude the whole period
194
197
  through `NOT BETWEEN`.
195
198
 
196
- Date digits may contain `%`, `?` or `*`. Patterns are reordered into SQL year-month-day order, `?` becomes `_` and `*`
197
- becomes `%`. For example `??/03/2020` becomes `2020-03-__%` in day/month order; the final `%` also permits stored times.
199
+ Date digits may contain `*`, `%`, `?` or `_`. Patterns are reordered into SQL year-month-day order, `?` becomes `_` and
200
+ `*` becomes `%`. For example, `??/03/2020` and `__/03/2020` become `2020-03-__%` in day/month order.
201
+ The final `%` also permits stored times.
198
202
  Each wildcard counts as one digit while identifying the input format and completing date fields. For example,
199
203
  `??` selects month patterns in the current year, `????` selects year patterns, and a two-character year such as `**`
200
204
  is prefixed with the current century before replacing the wildcards. One-character month and day fields are zero-padded.
201
- The prefixes `!`, `!=` and `<>` use `NOT LIKE` for these patterns.
202
- On a date property, `?` alone excludes the zero date; `!?`, `!=?` and `<>?` find zero dates.
205
+ On dates, the prefixes `!`, `!=`, `<>` and `≠` use `NOT LIKE` for these patterns.
206
+ On a date property, a lone `?` or `_` finds filled-in dates. With any of those prefixes, it finds empty dates.
203
207
  Empty dates are stored as `0000-00-00`, never SQL `NULL`.
204
208
  Invalid dates match no rows, without calendar rollover.
205
209
  Original input text is retained in session and restored for subsequent feed requests.
@@ -97,7 +97,7 @@ function datePeriod(value, format, now) {
97
97
  };
98
98
  }
99
99
  function dateSearch(value, operator = '=', now = new Date(), format = (0, translate_1.tr)('dd/MM/yyyy', { ucFirst: false })) {
100
- value = value.trim();
100
+ value = value.trim().replaceAll('_', '?');
101
101
  if (value === '?') {
102
102
  return ['!', '!=', '<>'].includes(operator)
103
103
  ? (0, sql_functions_2.equal)('0000-00-00')
@@ -1,5 +1,6 @@
1
1
  <!--criteria-->
2
- <span class="list-filter-icon" aria-hidden="true"></span>
2
+ <button aria-label="Edit the filter" class="list-filter-icon" data-focus-column-filter
3
+ title="Edit the filter" type="button"></button>
3
4
  <span aria-label="Active list filters" class="list-filter-text" role="group"
4
5
  ><!--items--><code class="list-filter-criterion"
5
6
  >{caption}<span class="list-filter-value">{value}</span></code>{space}<!--end--></span>
package/cjs/filter.d.ts CHANGED
@@ -2,9 +2,9 @@ import { Type } from '@itrocks/class-type';
2
2
  import { Request } from '@itrocks/request-response';
3
3
  import { Option } from '@itrocks/storage';
4
4
  import { SearchType } from '@itrocks/storage';
5
+ import { SearchExpression } from './front/search-expression';
5
6
  import { Columns } from './columns';
6
7
  import { Parameter } from './parameter';
7
- import { SearchExpression } from './search-expression';
8
8
  type Search = {
9
9
  [property: string]: string;
10
10
  };
package/cjs/filter.js CHANGED
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Filter = void 0;
4
4
  const class_view_1 = require("@itrocks/class-view");
5
+ const property_type_1 = require("@itrocks/property-type");
6
+ const property_type_2 = require("@itrocks/property-type");
5
7
  const reflect_path_1 = require("@itrocks/reflect-path");
6
8
  const sql_functions_1 = require("@itrocks/sql-functions");
7
9
  const sql_functions_2 = require("@itrocks/sql-functions");
@@ -16,68 +18,98 @@ const sql_functions_10 = require("@itrocks/sql-functions");
16
18
  const sql_functions_11 = require("@itrocks/sql-functions");
17
19
  const sql_functions_12 = require("@itrocks/sql-functions");
18
20
  const sql_functions_13 = require("@itrocks/sql-functions");
21
+ const sql_functions_14 = require("@itrocks/sql-functions");
22
+ const sql_functions_15 = require("@itrocks/sql-functions");
19
23
  const translate_1 = require("@itrocks/translate");
24
+ const search_expression_1 = require("./front/search-expression");
25
+ const search_expression_2 = require("./front/search-expression");
20
26
  const date_search_1 = require("./date-search");
21
27
  const parameter_1 = require("./parameter");
22
- const search_expression_1 = require("./search-expression");
23
28
  const operators = {
24
- '!': sql_functions_11.notEqual,
25
- '!=': sql_functions_11.notEqual,
26
- '<': sql_functions_8.less,
27
- '<=': sql_functions_9.lessOrEqual,
28
- '<>': sql_functions_11.notEqual,
29
+ '!': sql_functions_13.notEqual,
30
+ '!=': sql_functions_13.notEqual,
31
+ '<': sql_functions_10.less,
32
+ '<=': sql_functions_11.lessOrEqual,
33
+ '<>': sql_functions_13.notEqual,
29
34
  '=': sql_functions_5.equal,
30
35
  '>': sql_functions_6.greater,
31
- '>=': sql_functions_7.greaterOrEqual
36
+ '>=': sql_functions_7.greaterOrEqual,
37
+ '≠': sql_functions_13.notEqual
32
38
  };
33
- function explicitSearchValue(propertyType, operator, value) {
34
- if (propertyType === Date)
35
- return (0, date_search_1.dateSearch)(value, operator === ':' ? '=' : operator);
36
- if (operator !== ':')
37
- return operators[operator](value);
38
- if (propertyType !== String)
39
+ function comparisonOperand(propertyType, value) {
40
+ if (propertyType !== Number || !/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i.test(value.trim())) {
39
41
  return value;
40
- return (0, sql_functions_10.like)(value.replace(/[\\%_]/g, '\\$&') + '%');
42
+ }
43
+ const number = Number(value);
44
+ return Number.isFinite(number) && (!Number.isInteger(number) || Number.isSafeInteger(number)) ? number : value;
45
+ }
46
+ function criterionValue(propertyType, value, operator) {
47
+ if (propertyType === Date) {
48
+ const comparison = operator === ':' ? '=' : operator === '≠' ? '!=' : operator;
49
+ const trimmed = value.trim();
50
+ if (trimmed && (comparison === '!=' || comparison === '<>') && (0, translate_1.trReverse)(trimmed.toLowerCase()) === 'empty') {
51
+ return (0, date_search_1.dateSearch)('?');
52
+ }
53
+ return (0, date_search_1.dateSearch)(value, comparison);
54
+ }
55
+ const compare = operator && operator !== ':' ? operators[operator] : undefined;
56
+ if ((!compare || operator === '!') && /[*?%_]/.test(value)) {
57
+ const match = operator === '!' ? sql_functions_14.notLike : sql_functions_12.like;
58
+ return match(value.replaceAll('*', '%').replaceAll('?', '_'));
59
+ }
60
+ if (operator === '!' && propertyType === String && value)
61
+ return (0, sql_functions_14.notLike)(value + '%');
62
+ if (compare)
63
+ return compare(comparisonOperand(propertyType, value));
64
+ const separator = operator === ':' ? -1 : value.indexOf('-');
65
+ if (separator >= 0) {
66
+ const lower = value.slice(0, separator).trim();
67
+ const upper = value.slice(separator + 1).trim();
68
+ if (lower && upper)
69
+ return (0, sql_functions_4.between)(comparisonOperand(propertyType, lower), comparisonOperand(propertyType, upper));
70
+ if (lower)
71
+ return (0, sql_functions_7.greaterOrEqual)(comparisonOperand(propertyType, lower));
72
+ if (upper)
73
+ return (0, sql_functions_11.lessOrEqual)(comparisonOperand(propertyType, upper));
74
+ return propertyType === Number ? (0, sql_functions_15.or)() : (0, sql_functions_5.equal)('-');
75
+ }
76
+ if (propertyType !== String)
77
+ return comparisonOperand(propertyType, value);
78
+ if (!value)
79
+ return (0, sql_functions_5.equal)('');
80
+ return (0, sql_functions_12.like)((operator === ':' ? value.replaceAll('\\', '\\\\') : value) + '%');
81
+ }
82
+ function emptyCriterion(value, date = false) {
83
+ const alias = value.trim().match(date ? /^(!=|<>|[!≠])?\s*(.+)$/s : /^(!)?\s*(.+)$/s);
84
+ if (alias && (0, translate_1.trReverse)(alias[2].toLowerCase()) === 'empty')
85
+ return alias[1] ? 'present' : 'empty';
86
+ }
87
+ function scalarType(type) {
88
+ if (type instanceof property_type_2.UnionType) {
89
+ const members = type.types.filter(member => !(0, property_type_1.isLiteral)(member, null) && !(0, property_type_1.isLiteral)(member, undefined));
90
+ if (members.length === 1)
91
+ return members[0].type;
92
+ }
93
+ return type.type;
41
94
  }
42
95
  function searchValue(propertyType, expression) {
43
96
  if (!('value' in expression)) {
44
- const combine = (expression.operator === 'AND') ? sql_functions_3.and : sql_functions_13.or;
45
- return combine(...expression.operands.map(operand => searchValue(propertyType, operand) ?? (0, sql_functions_13.or)()));
97
+ const combine = (expression.operator === 'AND') ? sql_functions_3.and : sql_functions_15.or;
98
+ return combine(...expression.operands.map(operand => searchValue(propertyType, operand) ?? (0, sql_functions_15.or)()));
46
99
  }
47
100
  if (expression.comparison !== undefined) {
48
- return explicitSearchValue(propertyType, expression.comparison, expression.value);
101
+ return criterionValue(propertyType, expression.value, expression.comparison);
49
102
  }
50
103
  let value = expression.value;
51
- const alias = value.trim().match(/^(!=|<>|!)?\s*(.+)$/s);
52
- if (alias && ((0, translate_1.trReverse)(alias[2].toLowerCase()) === 'empty')) {
53
- value = (alias[1] ? '' : '!') + ((propertyType === Date) ? '?' : '?*');
104
+ const empty = emptyCriterion(value, propertyType === Date);
105
+ if (empty) {
106
+ if (propertyType === Number)
107
+ return empty === 'empty' ? (0, sql_functions_9.isNull)() : (0, sql_functions_8.isNotNull)();
108
+ value = (empty === 'present' ? '' : '!') + ((propertyType === Date) ? '?' : '?*');
54
109
  }
55
- const comparison = value.match(/^(>=|<=|<>|!=|>|<|=|!)(.*)$/s);
56
- const operator = comparison ? operators[comparison[1]] : undefined;
110
+ const comparison = value.match(search_expression_1.columnComparison);
57
111
  const operand = comparison ? comparison[2].trim() : value;
58
- if (propertyType === Date) {
59
- return (0, date_search_1.dateSearch)(operand, comparison?.[1]);
60
- }
61
- if (/[*?]/.test(operand) && (!operator || operator === sql_functions_11.notEqual)) {
62
- const compare = operator ? sql_functions_12.notLike : sql_functions_10.like;
63
- return compare(operand.replaceAll('*', '%').replaceAll('?', '_'));
64
- }
65
- if (operator) {
66
- return operator(operand);
67
- }
68
- const separator = value.indexOf('-');
69
- if (separator < 0) {
70
- const text = (propertyType === String);
71
- return (text ? (0, sql_functions_10.like)(value + '%') : value);
72
- }
73
- const lower = value.slice(0, separator).trim();
74
- const upper = value.slice(separator + 1).trim();
75
- if (lower && upper)
76
- return (0, sql_functions_4.between)(lower, upper);
77
- if (lower)
78
- return (0, sql_functions_7.greaterOrEqual)(lower);
79
- if (upper)
80
- return (0, sql_functions_9.lessOrEqual)(upper);
112
+ return criterionValue(propertyType, operand, comparison?.[1]);
81
113
  }
82
114
  class Filter extends parameter_1.Parameter {
83
115
  columns;
@@ -89,29 +121,32 @@ class Filter extends parameter_1.Parameter {
89
121
  columnCondition(type, property, value) {
90
122
  let expression;
91
123
  try {
92
- expression = (0, search_expression_1.searchExpression)(value);
124
+ expression = (0, search_expression_2.searchExpression)(value);
93
125
  }
94
126
  catch (error) {
95
127
  if (!(error instanceof SyntaxError))
96
128
  throw error;
97
- return { [property]: (0, sql_functions_13.or)() };
129
+ return { [property]: (0, sql_functions_15.or)() };
98
130
  }
99
- const resolved = (0, reflect_path_1.resolvePropertyPath)(type, property);
100
- if (resolved.target)
101
- return this.condition(type, property, expression);
102
- const criterion = searchValue(resolved.property.type.type, expression);
103
- return (criterion === undefined) ? {} : { [property]: criterion };
131
+ return this.condition(type, property, expression);
104
132
  }
105
133
  condition(type, property, expression, ancestors = []) {
106
134
  const resolved = (0, reflect_path_1.resolvePropertyPath)(type, property);
107
135
  if (!resolved.target) {
108
- const value = searchValue(resolved.property.type.type, expression);
109
- return { [property]: value ?? (0, sql_functions_13.or)() };
136
+ const value = searchValue(scalarType(resolved.property.type), expression);
137
+ if (value === undefined && !ancestors.length)
138
+ return {};
139
+ return { [property]: value ?? (0, sql_functions_15.or)() };
110
140
  }
111
141
  if (!('value' in expression)) {
112
142
  const operator = (expression.operator === 'AND') ? sql_functions_1.AND : sql_functions_2.OR;
113
143
  return { [operator]: expression.operands.map(operand => this.condition(type, property, operand, ancestors)) };
114
144
  }
145
+ if (resolved.targetMultiplicity === 'one' && expression.comparison === undefined) {
146
+ const empty = emptyCriterion(expression.value);
147
+ if (empty)
148
+ return { [property]: empty === 'empty' ? (0, sql_functions_9.isNull)() : (0, sql_functions_8.isNotNull)() };
149
+ }
115
150
  if (ancestors.includes(resolved.target))
116
151
  throw new Error(`Cyclic search representation: ${property}`);
117
152
  const branch = [...ancestors, resolved.target];
@@ -0,0 +1,10 @@
1
+ export type SearchComparison = ':' | '=' | '!' | '!=' | '<' | '<=' | '>' | '>=';
2
+ export type SearchExpression = {
3
+ comparison?: SearchComparison;
4
+ value: string;
5
+ } | {
6
+ operator: 'AND' | 'OR';
7
+ operands: SearchExpression[];
8
+ };
9
+ export declare const columnComparison: RegExp;
10
+ export declare function searchExpression(input: string): SearchExpression;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.columnComparison = void 0;
4
+ exports.searchExpression = searchExpression;
5
+ exports.columnComparison = /^(>=|<=|<>|!=|[><=!≠])(.*)$/s;
6
+ function searchExpression(input) {
7
+ // Preserve ordinary input exactly, including spaces used by existing scalar criteria.
8
+ if (!/[,|&+()"\\]/.test(input))
9
+ return { value: input };
10
+ return new SearchParser(input).parse();
11
+ }
12
+ class SearchParser {
13
+ input;
14
+ position = 0;
15
+ constructor(input) {
16
+ this.input = input;
17
+ }
18
+ and() {
19
+ const operands = [this.primary()];
20
+ while (this.take('&+'))
21
+ operands.push(this.primary());
22
+ return (operands.length === 1) ? operands[0] : { operator: 'AND', operands };
23
+ }
24
+ fail(message) {
25
+ throw new SyntaxError(`${message} at position ${this.position + 1}`);
26
+ }
27
+ or() {
28
+ const operands = [this.and()];
29
+ while (this.take(',|'))
30
+ operands.push(this.and());
31
+ return (operands.length === 1) ? operands[0] : { operator: 'OR', operands };
32
+ }
33
+ parse() {
34
+ const expression = this.or();
35
+ this.space();
36
+ if (this.position !== this.input.length)
37
+ this.fail('Unexpected character');
38
+ return expression;
39
+ }
40
+ primary() {
41
+ if (this.take('(')) {
42
+ const expression = this.or();
43
+ if (!this.take(')')) {
44
+ this.fail('Missing closing parenthesis');
45
+ }
46
+ return expression;
47
+ }
48
+ let value = '';
49
+ let length = 0;
50
+ let quoted = false;
51
+ let seen = false;
52
+ while (this.position < this.input.length) {
53
+ const character = this.input[this.position];
54
+ if (!quoted && ',|&+()'.includes(character))
55
+ break;
56
+ this.position++;
57
+ if ((character === '\\')
58
+ && (this.position < this.input.length)
59
+ && ',|&+()"\\'.includes(this.input[this.position])) {
60
+ value += this.input[this.position++];
61
+ length = value.length;
62
+ seen = true;
63
+ }
64
+ else if (character === '"') {
65
+ quoted = !quoted;
66
+ seen = true;
67
+ }
68
+ else {
69
+ value += character;
70
+ if (quoted || character.trim())
71
+ length = value.length;
72
+ seen ||= !!character.trim();
73
+ }
74
+ }
75
+ if (quoted)
76
+ this.fail('Unclosed quote');
77
+ if (!seen)
78
+ this.fail('Missing criterion');
79
+ return { value: value.slice(0, length) };
80
+ }
81
+ space() {
82
+ while ((this.position < this.input.length) && /\s/.test(this.input[this.position])) {
83
+ this.position++;
84
+ }
85
+ }
86
+ take(characters) {
87
+ this.space();
88
+ if ((this.position === this.input.length) || !characters.includes(this.input[this.position])) {
89
+ return false;
90
+ }
91
+ this.position++;
92
+ return true;
93
+ }
94
+ }
95
+ //# sourceMappingURL=search-expression.js.map
package/cjs/list.html CHANGED
@@ -41,7 +41,7 @@
41
41
  <thead>
42
42
  <tr class="properties">
43
43
  <th class="select" data-freeze><!--selection-->{{template}}<!--end-->
44
- <input class="search-submit" title="Search" type="submit" value="Search">
44
+ <input class="search-submit" title="Filter" type="submit" value="Filter">
45
45
  </th>
46
46
  <!--columns-->
47
47
  <th data-property="{name}" data-reverse="{?reverse}" data-sort="{?sort}"
package/list.css CHANGED
@@ -327,6 +327,9 @@ main > article[data-action=list] > header > .list-toolbar > .summary {
327
327
  }
328
328
 
329
329
  .list-filter {
330
+ --list-filter-criterion-color: #888;
331
+ --list-filter-value-background: #d5edff;
332
+ --list-filter-value-color: #12365b;
330
333
  align-items: center;
331
334
  display: flex;
332
335
  flex: 1;
@@ -335,20 +338,18 @@ main > article[data-action=list] > header > .list-toolbar > .summary {
335
338
  .list-filter .list-filter-icon {
336
339
  background: url("filter.svg") center/18px no-repeat;
337
340
  }
338
- .list-filter span.list-filter-icon {
341
+ .list-filter .list-filter-icon, .list-filter > .list-filter-reset {
342
+ box-sizing: border-box;
339
343
  flex: none;
340
- height: 18px;
341
- width: 18px;
344
+ height: 36px;
345
+ padding: 0;
346
+ width: 32px;
342
347
  }
343
348
  .list-filter button.list-filter-icon, .list-filter > .list-filter-reset {
344
349
  border: 0;
345
350
  border-radius: 2px;
346
351
  cursor: pointer;
347
- flex: none;
348
- height: 36px;
349
- padding: 0;
350
352
  touch-action: manipulation;
351
- width: 32px;
352
353
  }
353
354
  .list-filter button.list-filter-icon:hover, .list-filter > .list-filter-reset:hover {
354
355
  background-color: #eee;
@@ -364,7 +365,6 @@ main > article[data-action=list] > header > .list-toolbar > .summary {
364
365
  display: block;
365
366
  }
366
367
  .list-filter .list-filter-text {
367
- flex: 1;
368
368
  min-width: 0;
369
369
  overflow-x: auto;
370
370
  white-space: pre;
@@ -373,9 +373,9 @@ main > article[data-action=list] > header > .list-toolbar > .summary {
373
373
  font: inherit;
374
374
  }
375
375
  .list-filter .list-filter-criterion {
376
- text-decoration: underline dotted #888;
376
+ text-decoration: underline dotted var(--list-filter-criterion-color);
377
377
  }
378
378
  .list-filter .list-filter-value {
379
- background: #d5edff;
380
- color: #12365b;
379
+ background: var(--list-filter-value-background);
380
+ color: var(--list-filter-value-color);
381
381
  }
package/package.json CHANGED
@@ -15,6 +15,7 @@
15
15
  "@itrocks/decorator": "latest",
16
16
  "@itrocks/list-properties": "latest",
17
17
  "@itrocks/property-select": "latest",
18
+ "@itrocks/property-type": "latest",
18
19
  "@itrocks/property-view": "latest",
19
20
  "@itrocks/reflect": "latest",
20
21
  "@itrocks/reflect-path": "latest",
@@ -33,6 +34,7 @@
33
34
  "@itrocks/class-file": "latest",
34
35
  "@itrocks/fastify-file-session-store": "latest",
35
36
  "@types/node": "^24.10",
37
+ "pdf-lib": "^1.17.1",
36
38
  "sass": "^1.95",
37
39
  "typescript": "^7.0"
38
40
  },
@@ -49,6 +51,11 @@
49
51
  "./projection": "./cjs/projection.js",
50
52
  "./property-select.js": "./property-select.js",
51
53
  "./search": "./cjs/search.js",
54
+ "./search-expression.js": {
55
+ "types": "./cjs/front/search-expression.d.ts",
56
+ "require": "./cjs/front/search-expression.js",
57
+ "default": "./search-expression.js"
58
+ },
52
59
  "./selector-state": "./cjs/selector-state.js",
53
60
  "./selector-state.js": "./selector-state.js",
54
61
  "./session-state": "./cjs/session-state.js"
@@ -102,5 +109,5 @@
102
109
  "build:front": "tsc -p src/front/tsconfig.json",
103
110
  "test": "npm run build:cjs && node --test \"test/**/*.test.mjs\""
104
111
  },
105
- "version": "0.28.2"
112
+ "version": "0.29.0"
106
113
  }
@@ -0,0 +1,10 @@
1
+ export type SearchComparison = ':' | '=' | '!' | '!=' | '<' | '<=' | '>' | '>=';
2
+ export type SearchExpression = {
3
+ comparison?: SearchComparison;
4
+ value: string;
5
+ } | {
6
+ operator: 'AND' | 'OR';
7
+ operands: SearchExpression[];
8
+ };
9
+ export declare const columnComparison: RegExp;
10
+ export declare function searchExpression(input: string): SearchExpression;
@@ -0,0 +1,90 @@
1
+ export const columnComparison = /^(>=|<=|<>|!=|[><=!≠])(.*)$/s;
2
+ export function searchExpression(input) {
3
+ // Preserve ordinary input exactly, including spaces used by existing scalar criteria.
4
+ if (!/[,|&+()"\\]/.test(input))
5
+ return { value: input };
6
+ return new SearchParser(input).parse();
7
+ }
8
+ class SearchParser {
9
+ input;
10
+ position = 0;
11
+ constructor(input) {
12
+ this.input = input;
13
+ }
14
+ and() {
15
+ const operands = [this.primary()];
16
+ while (this.take('&+'))
17
+ operands.push(this.primary());
18
+ return (operands.length === 1) ? operands[0] : { operator: 'AND', operands };
19
+ }
20
+ fail(message) {
21
+ throw new SyntaxError(`${message} at position ${this.position + 1}`);
22
+ }
23
+ or() {
24
+ const operands = [this.and()];
25
+ while (this.take(',|'))
26
+ operands.push(this.and());
27
+ return (operands.length === 1) ? operands[0] : { operator: 'OR', operands };
28
+ }
29
+ parse() {
30
+ const expression = this.or();
31
+ this.space();
32
+ if (this.position !== this.input.length)
33
+ this.fail('Unexpected character');
34
+ return expression;
35
+ }
36
+ primary() {
37
+ if (this.take('(')) {
38
+ const expression = this.or();
39
+ if (!this.take(')')) {
40
+ this.fail('Missing closing parenthesis');
41
+ }
42
+ return expression;
43
+ }
44
+ let value = '';
45
+ let length = 0;
46
+ let quoted = false;
47
+ let seen = false;
48
+ while (this.position < this.input.length) {
49
+ const character = this.input[this.position];
50
+ if (!quoted && ',|&+()'.includes(character))
51
+ break;
52
+ this.position++;
53
+ if ((character === '\\')
54
+ && (this.position < this.input.length)
55
+ && ',|&+()"\\'.includes(this.input[this.position])) {
56
+ value += this.input[this.position++];
57
+ length = value.length;
58
+ seen = true;
59
+ }
60
+ else if (character === '"') {
61
+ quoted = !quoted;
62
+ seen = true;
63
+ }
64
+ else {
65
+ value += character;
66
+ if (quoted || character.trim())
67
+ length = value.length;
68
+ seen ||= !!character.trim();
69
+ }
70
+ }
71
+ if (quoted)
72
+ this.fail('Unclosed quote');
73
+ if (!seen)
74
+ this.fail('Missing criterion');
75
+ return { value: value.slice(0, length) };
76
+ }
77
+ space() {
78
+ while ((this.position < this.input.length) && /\s/.test(this.input[this.position])) {
79
+ this.position++;
80
+ }
81
+ }
82
+ take(characters) {
83
+ this.space();
84
+ if ((this.position === this.input.length) || !characters.includes(this.input[this.position])) {
85
+ return false;
86
+ }
87
+ this.position++;
88
+ return true;
89
+ }
90
+ }
package/search-focus.js CHANGED
@@ -42,6 +42,10 @@ build({
42
42
  priority: 2000,
43
43
  selector: 'article[data-action="list"] > form'
44
44
  });
45
+ build('.list-filter > button[data-focus-column-filter]', 'click', function () {
46
+ this.closest('article[data-action="list"]')
47
+ ?.querySelector(':scope > form input[data-property-filter]:enabled')?.focus();
48
+ });
45
49
  build('.list-filter > .list-filter-reset', 'click', function () {
46
50
  const form = this.closest('article[data-action="list"]')?.querySelector(':scope > form');
47
51
  if (!form)