viewkitjs 0.25.0 → 0.26.0-pr-770-2abf987

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.
Files changed (164) hide show
  1. package/fields/dist/messages.d.ts +38 -0
  2. package/fields/dist/messages.js +29 -0
  3. package/fields/dist/parse-number.d.ts +9 -0
  4. package/fields/dist/parse-number.js +23 -0
  5. package/fields/dist/query/exact-number.d.ts +5 -0
  6. package/fields/dist/query/exact-number.js +18 -0
  7. package/fields/dist/query/filter.d.ts +3 -0
  8. package/fields/dist/query/filter.js +2 -1
  9. package/fields/dist/query/fold.d.ts +2 -0
  10. package/fields/dist/query/fold.js +17 -1
  11. package/fields/dist/query/number.d.ts +8 -7
  12. package/fields/dist/query/number.js +30 -3
  13. package/fields/dist/query/read-rule.js +2 -1
  14. package/fields/dist/query/sort.js +17 -2
  15. package/fields/dist/testing/cases.js +8 -0
  16. package/fields/dist/testing/samples.js +1 -0
  17. package/fields/docs/guides/conventions.md +1 -1
  18. package/fields/docs/guides/queries.md +8 -2
  19. package/fields/docs/reference/fields.md +1 -1
  20. package/fields/docs/reference/query.md +5 -4
  21. package/fields/skills/viewkit/SKILL.md +1 -1
  22. package/package.json +2 -1
  23. package/postgres/dist/fold.js +10 -1
  24. package/postgres/dist/rules.js +30 -2
  25. package/postgres/dist/search.js +1 -1
  26. package/postgres/dist/value-rows.d.ts +15 -7
  27. package/postgres/dist/value-rows.js +30 -6
  28. package/postgres/docs/guides/field-map.md +3 -3
  29. package/views/dist/contract.d.ts +63 -1
  30. package/views/dist/contract.js +63 -0
  31. package/views/dist/controls/compound-editor/compound-editor.d.ts +88 -0
  32. package/views/dist/controls/compound-editor/compound-editor.js +35 -0
  33. package/views/dist/controls/compound-editor/keeping.d.ts +13 -0
  34. package/views/dist/controls/compound-editor/keeping.js +56 -0
  35. package/views/dist/controls/compound-editor/looks.d.ts +15 -0
  36. package/views/dist/controls/compound-editor/looks.js +18 -0
  37. package/views/dist/controls/compound-editor/map-parts-body.d.ts +15 -0
  38. package/views/dist/controls/compound-editor/map-parts-body.js +28 -0
  39. package/views/dist/controls/compound-editor/name-parts.d.ts +3 -0
  40. package/views/dist/controls/compound-editor/name-parts.js +100 -0
  41. package/views/dist/controls/compound-editor/name.d.ts +18 -0
  42. package/views/dist/controls/compound-editor/name.js +20 -0
  43. package/views/dist/controls/compound-editor/place-parts.d.ts +3 -0
  44. package/views/dist/controls/compound-editor/place-parts.js +220 -0
  45. package/views/dist/controls/compound-editor/place.d.ts +58 -0
  46. package/views/dist/controls/compound-editor/place.js +79 -0
  47. package/views/dist/controls/compound-editor/range-parts.d.ts +3 -0
  48. package/views/dist/controls/compound-editor/range-parts.js +117 -0
  49. package/views/dist/controls/compound-editor/range.d.ts +7 -0
  50. package/views/dist/controls/compound-editor/range.js +11 -0
  51. package/views/dist/controls/compound-editor/row.d.ts +15 -0
  52. package/views/dist/controls/compound-editor/row.js +12 -0
  53. package/views/dist/controls/compound-editor/shell.d.ts +18 -0
  54. package/views/dist/controls/compound-editor/shell.js +17 -0
  55. package/views/dist/controls/compound-editor/tokens.d.ts +48 -0
  56. package/views/dist/controls/compound-editor/tokens.js +14 -0
  57. package/views/dist/controls/compound-editor.css +79 -0
  58. package/views/dist/controls/controls.d.ts +12 -0
  59. package/views/dist/controls/controls.js +12 -0
  60. package/views/dist/controls/date-editor/calendar.d.ts +60 -0
  61. package/views/dist/controls/date-editor/calendar.js +132 -0
  62. package/views/dist/controls/date-editor/date-days.d.ts +25 -0
  63. package/views/dist/controls/date-editor/date-days.js +24 -0
  64. package/views/dist/controls/date-editor/date-editor.d.ts +64 -0
  65. package/views/dist/controls/date-editor/date-editor.js +300 -0
  66. package/views/dist/controls/date-editor/date-parts.d.ts +21 -0
  67. package/views/dist/controls/date-editor/date-parts.js +101 -0
  68. package/views/dist/controls/date-editor/looks.d.ts +21 -0
  69. package/views/dist/controls/date-editor/looks.js +22 -0
  70. package/views/dist/controls/date-editor/map-calendar.d.ts +2 -0
  71. package/views/dist/controls/date-editor/map-calendar.js +38 -0
  72. package/views/dist/controls/date-editor/map-date-body.d.ts +11 -0
  73. package/views/dist/controls/date-editor/map-date-body.js +38 -0
  74. package/views/dist/controls/date-editor/segments.d.ts +33 -0
  75. package/views/dist/controls/date-editor/segments.js +54 -0
  76. package/views/dist/controls/date-editor/tokens.d.ts +143 -0
  77. package/views/dist/controls/date-editor/tokens.js +38 -0
  78. package/views/dist/controls/date-editor/words.d.ts +32 -0
  79. package/views/dist/controls/date-editor/words.js +26 -0
  80. package/views/dist/controls/date-editor.css +197 -0
  81. package/views/dist/controls/field/field.d.ts +2 -1
  82. package/views/dist/controls/field/field.js +3 -2
  83. package/views/dist/controls/field.css +3 -9
  84. package/views/dist/controls/flag/flag.d.ts +6 -0
  85. package/views/dist/controls/flag/flag.js +21 -0
  86. package/views/dist/controls/flag/tokens.d.ts +23 -0
  87. package/views/dist/controls/flag/tokens.js +8 -0
  88. package/views/dist/controls/flag.css +13 -0
  89. package/views/dist/controls/index.d.ts +20 -2
  90. package/views/dist/controls/index.js +19 -2
  91. package/views/dist/controls/inline-input/inline-input.js +3 -1
  92. package/views/dist/controls/inline-input.css +1 -2
  93. package/views/dist/controls/input/input.d.ts +1 -1
  94. package/views/dist/controls/input/input.js +6 -4
  95. package/views/dist/controls/input.css +19 -48
  96. package/views/dist/controls/internal/phone.d.ts +16 -2
  97. package/views/dist/controls/internal/phone.js +18 -8
  98. package/views/dist/controls/internal/shell-hand.d.ts +6 -0
  99. package/views/dist/controls/internal/shell-hand.js +34 -0
  100. package/views/dist/controls/internal/shell.d.ts +7 -0
  101. package/views/dist/controls/internal/shell.js +4 -0
  102. package/views/dist/controls/internal/told-step.d.ts +14 -0
  103. package/views/dist/controls/internal/told-step.js +12 -0
  104. package/views/dist/controls/list.css +2 -8
  105. package/views/dist/controls/menu/menu.js +5 -5
  106. package/views/dist/controls/menu-list/menu-list.js +7 -6
  107. package/views/dist/controls/number-field/number-field.js +4 -3
  108. package/views/dist/controls/number-field.css +2 -8
  109. package/views/dist/controls/picker/looks.d.ts +1 -1
  110. package/views/dist/controls/picker/looks.js +4 -5
  111. package/views/dist/controls/picker/map-fields-body.d.ts +18 -0
  112. package/views/dist/controls/picker/map-fields-body.js +43 -0
  113. package/views/dist/controls/picker/map-picker.d.ts +27 -0
  114. package/views/dist/controls/picker/map-picker.js +71 -0
  115. package/views/dist/controls/picker/picker.d.ts +40 -0
  116. package/views/dist/controls/picker/picker.js +55 -27
  117. package/views/dist/controls/picker.css +6 -2
  118. package/views/dist/controls/popover/popover.js +3 -2
  119. package/views/dist/controls/select/select.js +11 -9
  120. package/views/dist/controls/select.css +2 -4
  121. package/views/dist/controls/switch/switch.js +3 -1
  122. package/views/dist/controls/switch.css +5 -15
  123. package/views/dist/controls/text-editor/check.d.ts +42 -0
  124. package/views/dist/controls/text-editor/check.js +50 -0
  125. package/views/dist/controls/text-editor/countries.d.ts +7 -0
  126. package/views/dist/controls/text-editor/countries.js +11 -0
  127. package/views/dist/controls/text-editor/looks.d.ts +14 -0
  128. package/views/dist/controls/text-editor/looks.js +17 -0
  129. package/views/dist/controls/text-editor/map-text-body.d.ts +6 -0
  130. package/views/dist/controls/text-editor/map-text-body.js +13 -0
  131. package/views/dist/controls/text-editor/phone-number.d.ts +32 -0
  132. package/views/dist/controls/text-editor/phone-number.js +72 -0
  133. package/views/dist/controls/text-editor/text-editor.d.ts +50 -0
  134. package/views/dist/controls/text-editor/text-editor.js +275 -0
  135. package/views/dist/controls/text-editor/tokens.d.ts +63 -0
  136. package/views/dist/controls/text-editor/tokens.js +18 -0
  137. package/views/dist/controls/text-editor.css +83 -0
  138. package/views/dist/controls/tokens.js +8 -0
  139. package/views/dist/editors/DateEditor.js +3 -1
  140. package/views/dist/editors/SelectEditor.js +1 -1
  141. package/views/dist/internal/phone-line.d.ts +5 -0
  142. package/views/dist/internal/phone-line.js +4 -0
  143. package/views/dist/looks/index.d.ts +3 -0
  144. package/views/dist/looks/index.js +3 -0
  145. package/views/dist/looks/pieces.js +6 -0
  146. package/views/dist/model/column-filters.js +3 -2
  147. package/views/dist/provider/ViewsProvider.js +2 -2
  148. package/views/dist/provider/components.d.ts +4 -0
  149. package/views/dist/provider/desktop.d.ts +2 -2
  150. package/views/dist/provider/desktop.js +1 -1
  151. package/views/dist/provider/missing-slot.d.ts +1 -1
  152. package/views/dist/provider/missing-slot.js +1 -1
  153. package/views/dist/styles.css +370 -103
  154. package/views/dist/styles.unlayered.css +370 -103
  155. package/views/docs/contract.md +8 -7
  156. package/views/docs/controls/compound-editor.md +19 -0
  157. package/views/docs/controls/date-editor.md +43 -0
  158. package/views/docs/controls/flag.md +13 -0
  159. package/views/docs/controls/text-editor.md +23 -0
  160. package/views/docs/reference/controls.md +146 -3
  161. package/views/docs/reference/editors-date.md +1 -1
  162. package/views/docs/reference/looks.md +10 -1
  163. package/views/docs/reference/react.md +5 -5
  164. package/views/docs/reference/views.md +1 -1
@@ -152,6 +152,44 @@ export type FieldMessage = {
152
152
  key: "time.placeholder";
153
153
  } | {
154
154
  key: "time.label";
155
+ }
156
+ /** The Date editor's words beyond its quick days (ViewKit's default date body, CONTROLS.DateBody). */
157
+ | {
158
+ key: "date.type";
159
+ } | {
160
+ key: "date.none";
161
+ } | {
162
+ key: "date.add-time";
163
+ } | {
164
+ key: "date.last-month";
165
+ } | {
166
+ key: "date.next-month";
167
+ } | {
168
+ key: "date.day";
169
+ } | {
170
+ key: "date.month";
171
+ } | {
172
+ key: "date.year";
173
+ } | {
174
+ key: "date.months";
175
+ } | {
176
+ key: "date.years";
177
+ } | {
178
+ key: "time.hour";
179
+ } | {
180
+ key: "time.minute";
181
+ }
182
+ /** A typed line that is no date. */
183
+ | {
184
+ key: "date.not-a-date";
185
+ }
186
+ /** A typed day its month doesn't have: the month's name, and the day. */
187
+ | {
188
+ key: "date.no-such-day";
189
+ values: {
190
+ month: string;
191
+ day: number;
192
+ };
155
193
  } | {
156
194
  key: "chips.add-placeholder";
157
195
  } | {
@@ -151,6 +151,7 @@ const DUE_BUCKET_WORD = {
151
151
  next_7_days: "Next 7 days",
152
152
  next_30_days: "Next 30 days",
153
153
  };
154
+ const ordinal = (n) => `${n}${n % 10 === 1 && n !== 11 ? "st" : n % 10 === 2 && n !== 12 ? "nd" : n % 10 === 3 && n !== 13 ? "rd" : "th"}`;
154
155
  export const resolveFieldMessage = (message) => {
155
156
  switch (message.key) {
156
157
  case "lock.system":
@@ -245,6 +246,34 @@ export const resolveFieldMessage = (message) => {
245
246
  return "HH:MM";
246
247
  case "time.label":
247
248
  return "Time";
249
+ case "date.type":
250
+ return "Type a date";
251
+ case "date.none":
252
+ return "No date";
253
+ case "date.add-time":
254
+ return "Add time";
255
+ case "date.last-month":
256
+ return "Last month";
257
+ case "date.next-month":
258
+ return "Next month";
259
+ case "date.day":
260
+ return "Day";
261
+ case "date.month":
262
+ return "Month";
263
+ case "date.year":
264
+ return "Year";
265
+ case "date.months":
266
+ return "Months";
267
+ case "date.years":
268
+ return "Years";
269
+ case "time.hour":
270
+ return "Hour";
271
+ case "time.minute":
272
+ return "Minute";
273
+ case "date.not-a-date":
274
+ return "That isn't a date. Write a day and a month: 12/11";
275
+ case "date.no-such-day":
276
+ return `${message.values.month} has no ${ordinal(message.values.day)}. Write a day and a month: 12/11`;
248
277
  case "chips.add-placeholder":
249
278
  return "Add a value…";
250
279
  case "chips.everything-picked":
@@ -49,6 +49,15 @@ export declare function numberOfDecimalText(text: string): number | null;
49
49
  * "below the minimum" serves the definition and the two gates.
50
50
  */
51
51
  export declare function compareDecimalText(a: string, b: string): number;
52
+ /**
53
+ * Canonical decimal text rounded EXACTLY to `decimals` fraction digits, half away
54
+ * from zero, as Postgres' `round(numeric, d)` rounds: "1.005" at 2 is "1.01",
55
+ * which `toFixed` on the double makes "1.00". Padded with zeros when it carries
56
+ * fewer. Digits only, no float, and never a signed zero.
57
+ *
58
+ * Internal: what a number rule's "is" rounds decimal text to (`matchesNumberRule`).
59
+ */
60
+ export declare function roundDecimalText(text: string, decimals: number): string;
52
61
  /** How many fraction digits canonical text CARRIES, trailing zeros not counted:
53
62
  * "120.500" carries two and "120.0" none, because a zero at the end is a
54
63
  * column's padding, not a digit somebody typed. Exact — no float involved. */
@@ -134,6 +134,29 @@ export function compareDecimalText(a, b) {
134
134
  return 0;
135
135
  return leftFraction < rightFraction ? -sign : sign;
136
136
  }
137
+ export function roundDecimalText(text, decimals) {
138
+ const negative = text.startsWith("-");
139
+ const body = negative ? text.slice(1) : text;
140
+ const point = body.indexOf(".");
141
+ const whole = point < 0 ? body : body.slice(0, point);
142
+ const fraction = point < 0 ? "" : body.slice(point + 1);
143
+ let digits = whole + fraction.padEnd(decimals, "0").slice(0, decimals);
144
+ if ((fraction[decimals] ?? "0") >= "5") {
145
+ const carried = digits.split("");
146
+ let i = carried.length - 1;
147
+ while (i >= 0 && carried[i] === "9")
148
+ carried[i--] = "0";
149
+ if (i >= 0)
150
+ carried[i] = String(Number(carried[i]) + 1);
151
+ else
152
+ carried.unshift("1");
153
+ digits = carried.join("");
154
+ }
155
+ const cut = digits.length - decimals;
156
+ const rounded = decimals === 0 ? digits : `${digits.slice(0, cut)}.${digits.slice(cut)}`;
157
+ const tidy = rounded.replace(/^0+(?=\d)/, "");
158
+ return negative ? withoutNegativeZero(`-${tidy}`) : tidy;
159
+ }
137
160
  export function decimalFractionDigits(text) {
138
161
  const point = text.indexOf(".");
139
162
  if (point < 0)
@@ -0,0 +1,5 @@
1
+ /** `value` as canonical decimal text, or null when it reads as no number: absent, blank, malformed or not finite. */
2
+ export declare function exactNumberText(value: unknown): string | null;
3
+ /** Whether `value` reads as no number, as `exactNumberText` reads it. A JS number always reads as one, an infinity
4
+ * included, so it sorts as a value, as a database sorts it. */
5
+ export declare function readsAsNoNumber(value: unknown): boolean;
@@ -0,0 +1,18 @@
1
+ import { decimalTextOf, isDecimalText, parseNumber } from "../parse-number.js";
2
+ const MACHINE_NUMBER = /^[+-]?(\d+\.?\d*|\.\d+)$/;
3
+ export function exactNumberText(value) {
4
+ if (typeof value === "number")
5
+ return decimalTextOf(value);
6
+ if (typeof value !== "string")
7
+ return null;
8
+ const text = value.trim();
9
+ if (text === "")
10
+ return null;
11
+ if (isDecimalText(text))
12
+ return text;
13
+ const read = MACHINE_NUMBER.test(text) ? Number(text) : parseNumber(text);
14
+ return read == null ? null : decimalTextOf(read);
15
+ }
16
+ export function readsAsNoNumber(value) {
17
+ return typeof value === "number" ? false : exactNumberText(value) === null;
18
+ }
@@ -99,6 +99,8 @@ export type MatchOptions = {
99
99
  decimals?: number;
100
100
  now?: Date;
101
101
  conventions?: FieldConventions;
102
+ /** The field keeps decimal text (`storesDecimalText`): a number rule compares its text exactly. */
103
+ exact?: boolean;
102
104
  };
103
105
  /**
104
106
  * A date rule as it sits in a `FilterTree`, as the flat `DateFilterRule` that
@@ -118,6 +120,7 @@ export type RuleReader = (rule: FilterRule) => {
118
120
  type: FieldType;
119
121
  value: unknown;
120
122
  decimals?: number;
123
+ exact?: boolean;
121
124
  } | undefined;
122
125
  /** One record as a tree reads it: its own fields, and the records its relations hold, for a rule across a
123
126
  * relation. A record whose reader hands in no related records gives such a rule no opinion. */
@@ -364,7 +364,7 @@ export function matchesRule(type, value, rule, opts = {}) {
364
364
  case "number":
365
365
  case "percent":
366
366
  case "currency":
367
- return matchesNumberRule(value, numberRule(rule), opts.decimals ?? 2);
367
+ return matchesNumberRule(value, numberRule(rule), opts.decimals ?? 2, opts.exact ?? false);
368
368
  case "date":
369
369
  case "datetime":
370
370
  return matchesDateRule(value, dateFilterRuleOf(rule), opts.now ?? new Date(), type, opts.conventions ?? DEFAULT_CONVENTIONS);
@@ -435,6 +435,7 @@ function matchesNode(node, record, opts) {
435
435
  return matchesRule(field.type, field.value, node, {
436
436
  ...opts,
437
437
  decimals: field.decimals ?? opts.decimals,
438
+ exact: field.exact ?? opts.exact,
438
439
  });
439
440
  }
440
441
  function holdsValue(value) {
@@ -1 +1,3 @@
1
+ /** The lowercase letters with no combining form, and their plain spelling. */
2
+ export declare const FOLDED_LETTERS: Readonly<Record<string, string>>;
1
3
  export declare function foldText(value: string): string;
@@ -1,4 +1,20 @@
1
1
  const LATIN_MARKS = /[\u{300}-\u{36f}]/gu;
2
+ export const FOLDED_LETTERS = {
3
+ ł: "l",
4
+ ø: "o",
5
+ đ: "d",
6
+ ð: "d",
7
+ ı: "i",
8
+ ß: "ss",
9
+ æ: "ae",
10
+ œ: "oe",
11
+ þ: "th",
12
+ };
13
+ const LETTERS = new RegExp(`[${Object.keys(FOLDED_LETTERS).join("")}]`, "gu");
2
14
  export function foldText(value) {
3
- return value.normalize("NFD").replace(LATIN_MARKS, "").toLowerCase();
15
+ return value
16
+ .normalize("NFKD")
17
+ .replace(LATIN_MARKS, "")
18
+ .toLowerCase()
19
+ .replace(LETTERS, (letter) => FOLDED_LETTERS[letter]);
4
20
  }
@@ -83,12 +83,13 @@ export declare function ruleDecimalsOf(field: FieldDef): number;
83
83
  * Equality rounds BOTH sides to the column's displayed decimals. After an FX
84
84
  * conversion nothing lands on a round number, so `= 100` against a cell reading
85
85
  * €100.00 would otherwise return nothing — the one result guaranteed to read as
86
- * broken. Comparisons need no such help.
86
+ * broken. Comparisons need no such help. "Is not" keeps an empty value, as every
87
+ * type's "not" rule does; "is" and the comparisons never keep one.
87
88
  *
88
- * Everything here is judged as a NUMBER, the text a column stores included, so
89
- * past 2^53 the comparison is lossy: two decimal texts that differ in a digit
90
- * that far out read as the same double and match the same rules. That is the
91
- * stated limit of filtering what the cell draws; the exact digits are the two
92
- * acceptance gates' business, and they compare the text itself.
89
+ * A value is judged as the double it is or spells ("120.50", "€1,234.50"), as
90
+ * a database compares a number field. With `exact`, the field keeps decimal
91
+ * text (`storage: "decimal"`, `storesDecimalText`), and its canonical text is
92
+ * judged EXACTLY, as digits: past 2^53 and beyond a double's range alike, and
93
+ * its equality rounds half away from zero, as Postgres rounds a numeric.
93
94
  */
94
- export declare function matchesNumberRule(value: unknown, rule: NumberFilterRule | null | undefined, decimals?: number): boolean;
95
+ export declare function matchesNumberRule(value: unknown, rule: NumberFilterRule | null | undefined, decimals?: number, exact?: boolean): boolean;
@@ -1,6 +1,6 @@
1
1
  import { DEFAULT_CONVENTIONS, conventionsOr } from "../conventions.js";
2
2
  import { isIntegerField, presentedDef } from "../derived.js";
3
- import { parseNumber } from "../parse-number.js";
3
+ import { compareDecimalText, decimalTextOf, isDecimalText, parseNumber, roundDecimalText } from "../parse-number.js";
4
4
  export { parseNumber } from "../parse-number.js";
5
5
  export const NUMBER_FILTER_OPERATORS = [
6
6
  { value: "eq", label: "Is", inputs: 1 },
@@ -146,7 +146,31 @@ export function ruleDecimalsOf(field) {
146
146
  return decimals;
147
147
  return def.type === "percent" ? 0 : 2;
148
148
  }
149
- export function matchesNumberRule(value, rule, decimals = 2) {
149
+ function matchesDecimalText(text, rule, decimals) {
150
+ const bound = (n) => decimalTextOf(n);
151
+ const against = (n) => compareDecimalText(text, bound(n));
152
+ switch (rule.operator) {
153
+ case "eq":
154
+ case "neq": {
155
+ const same = compareDecimalText(roundDecimalText(text, decimals), roundDecimalText(bound(rule.value), decimals)) === 0;
156
+ return rule.operator === "eq" ? same : !same;
157
+ }
158
+ case "gt":
159
+ return against(rule.value) > 0;
160
+ case "gte":
161
+ return against(rule.value) >= 0;
162
+ case "lt":
163
+ return against(rule.value) < 0;
164
+ case "lte":
165
+ return against(rule.value) <= 0;
166
+ case "between": {
167
+ const [low, high] = [rule.value, rule.value2].sort((a, b) => a - b);
168
+ return against(low) >= 0 && against(high) <= 0;
169
+ }
170
+ }
171
+ return true;
172
+ }
173
+ export function matchesNumberRule(value, rule, decimals = 2, exact = false) {
150
174
  if (!isNumberRuleActive(rule))
151
175
  return true;
152
176
  const subject = toNumber(value);
@@ -155,7 +179,10 @@ export function matchesNumberRule(value, rule, decimals = 2) {
155
179
  if (rule.operator === "is_not_empty")
156
180
  return subject != null;
157
181
  if (subject == null)
158
- return false;
182
+ return rule.operator === "neq";
183
+ const text = typeof value === "string" ? value.trim() : null;
184
+ if (exact && text !== null && isDecimalText(text))
185
+ return matchesDecimalText(text, rule, decimals);
159
186
  const target = rule.value;
160
187
  const round = (v) => Number(v.toFixed(decimals));
161
188
  switch (rule.operator) {
@@ -1,4 +1,4 @@
1
- import { isPerCodeCurrency, knownField, scalarOf, valueTypeOf } from "../derived.js";
1
+ import { isPerCodeCurrency, knownField, scalarOf, storesDecimalText, valueTypeOf } from "../derived.js";
2
2
  export function ruleReaderOf(row, reader) {
3
3
  return (rule) => {
4
4
  const field = knownField(reader.fieldOf(rule.fieldKey));
@@ -8,6 +8,7 @@ export function ruleReaderOf(row, reader) {
8
8
  type: valueTypeOf(field),
9
9
  value: scalarOf(field, reader.read(row, rule.fieldKey)),
10
10
  decimals: reader.decimalsOf?.(rule.fieldKey),
11
+ exact: storesDecimalText(field),
11
12
  };
12
13
  };
13
14
  }
@@ -7,8 +7,11 @@ import { isEmptyName, namePart, nameText } from "../name.js";
7
7
  import { LOCATION_ORDERS, locationSortText } from "./location.js";
8
8
  import { isOpenVocabulary, statusOptionOrder } from "../options.js";
9
9
  import { phoneMatchText } from "../phone.js";
10
+ import { compareDecimalText } from "../parse-number.js";
11
+ import { exactNumberText, readsAsNoNumber } from "./exact-number.js";
10
12
  import { textOrderOf } from "./collate.js";
11
13
  import { mainItem, valueItems } from "../value-list.js";
14
+ const NUMBER_TYPES = new Set(["number", "percent", "currency"]);
12
15
  function isEmpty(v) {
13
16
  return v == null || v === "" || (Array.isArray(v) && valueItems(v).length === 0);
14
17
  }
@@ -34,7 +37,18 @@ function mainOf(v) {
34
37
  function firstOf(v) {
35
38
  return Array.isArray(v) ? v[0] : v;
36
39
  }
37
- const number = nullsLast((a, b) => Number(a) - Number(b));
40
+ const infinitySide = (v) => (typeof v === "number" && (v === Infinity || v === -Infinity) ? Math.sign(v) : 0);
41
+ const number = (a, b) => {
42
+ if (typeof a === "number" && typeof b === "number")
43
+ return a === b ? 0 : a < b ? -1 : a > b ? 1 : 0;
44
+ const ia = infinitySide(a), ib = infinitySide(b);
45
+ if (ia !== 0 || ib !== 0)
46
+ return ia - ib;
47
+ const ta = exactNumberText(a), tb = exactNumberText(b);
48
+ if (ta === null || tb === null)
49
+ return ta === tb ? 0 : ta === null ? 1 : -1;
50
+ return compareDecimalText(ta, tb);
51
+ };
38
52
  const instant = nullsLast((a, b) => new Date(String(a)).getTime() - new Date(String(b)).getTime());
39
53
  const boolean = nullsLast((a, b) => Number(a === true) - Number(b === true));
40
54
  function relationLabel(v) {
@@ -235,6 +249,7 @@ export function compareBy(sorts, reader, cv = DEFAULT_CONVENTIONS) {
235
249
  cmp: comparatorFor(field, cv, spec.by),
236
250
  emptyName: valueTypeOf(field) === "name",
237
251
  emptyRange: valueTypeOf(field) === "range",
252
+ emptyNumber: NUMBER_TYPES.has(valueTypeOf(field)) && !isPerCodeCurrency(presented),
238
253
  denominationOf: money && denominationReader(reader, spec.fieldKey, money),
239
254
  codeOrder: money && codeOrderFor(reader, money, cv),
240
255
  };
@@ -242,7 +257,7 @@ export function compareBy(sorts, reader, cv = DEFAULT_CONVENTIONS) {
242
257
  return (a, b) => {
243
258
  for (const step of steps) {
244
259
  const va = scalarOf(step.field, reader.read(a, step.key)), vb = scalarOf(step.field, reader.read(b, step.key));
245
- const ea = isEmpty(va) || (step.emptyName && isEmptyName(firstOf(va))) || (step.emptyRange && isEmptyRange(va)), eb = isEmpty(vb) || (step.emptyName && isEmptyName(firstOf(vb))) || (step.emptyRange && isEmptyRange(vb));
260
+ const ea = isEmpty(va) || (step.emptyName && isEmptyName(firstOf(va))) || (step.emptyRange && isEmptyRange(va)) || (step.emptyNumber && readsAsNoNumber(va)), eb = isEmpty(vb) || (step.emptyName && isEmptyName(firstOf(vb))) || (step.emptyRange && isEmptyRange(vb)) || (step.emptyNumber && readsAsNoNumber(vb));
246
261
  if (ea !== eb)
247
262
  return ea ? 1 : -1;
248
263
  if (!ea && step.denominationOf && step.codeOrder) {
@@ -42,6 +42,9 @@ function filterCases(samples) {
42
42
  rows("a whole range's high end not at a fraction", and({ fieldKey: "size", part: "high", operator: "neq", value: 49.6 })),
43
43
  rows("a percent at a fraction is read at no decimals", and(rule("progress", "eq", 12.6))),
44
44
  rows("a date is not a day keeps the undated", and(rule("due", "is_not", "2026-03-01"))),
45
+ rows("a number is not a value keeps the empty", and(rule("score", "neq", 10))),
46
+ rows("an amount is not zero keeps the empty", and(rule("amount", "neq", 0))),
47
+ rows("a percent is not a value keeps the empty", and(rule("progress", "neq", 50))),
45
48
  rows("a date-and-time is not a day, in the reader's zone", and(rule("touched", "is_not", "2026-03-01"))),
46
49
  rows("by a lookup of a lookup", and(rule("company_parent_city", "is", "London"))),
47
50
  rows("by a formula over a lookup", and(rule("city_shout", "is", "LONDON"))),
@@ -67,6 +70,11 @@ function searchCases(samples) {
67
70
  return [
68
71
  search("two words in two fields", "acme london"),
69
72
  search("stefan finds Ștefan", "stefan"),
73
+ search("lodz finds Łódź", "lodz"),
74
+ search("oresund finds Øresund", "oresund"),
75
+ search("strasse finds Straße", "strasse"),
76
+ search("dang finds Đặng", "dang"),
77
+ search("aesir finds Æsir", "aesir"),
70
78
  search("punctuation between words", "Acme - London"),
71
79
  search("a word only in an option's label", "proposal"),
72
80
  search("a word only in a relation's label", "coral"),
@@ -182,6 +182,7 @@ const TITLES = [
182
182
  "Ana", "ana", "Ána", "Ștefan", "stefan", "Émile", "Acme - London", "Zeta deal", "beta", "Beta", "", null,
183
183
  "Omega", "omega", "Échange", "Bolt renewal", "Delta pilot", "Iris", "iris", "Ödön", "Zoë", "zoe",
184
184
  "Mara", "mara", "Radu", "Sorin", "Șerban", "Tudor", "Lia", "lia", "Nora", "Riverside", "Nora Lee", "Ursu", "Vlad", "Wren",
185
+ "Łódź", "Øresund", "Straße", "Đặng", "Æsir",
185
186
  ];
186
187
  const NOTES = ["Met at **London** fair", "", null, "Follow up in *March*", "Bolt intro"];
187
188
  const WEBSITES = ["https://acme.com", "https://acme.com/about", "", null, "https://www.linkedin.com/company/zeta", "https://bolt.io"];
@@ -102,7 +102,7 @@ assert.equal(
102
102
 
103
103
  ## `language`
104
104
 
105
- The language is a BCP 47 tag too: the language your interface reads in. The names the library writes from data are in it, a place's country and region, and so is the month's word in a date filter's summary and in a date group's heading, while dates' order and digits, numbers and the order text sorts in keep `locale`. So an app that writes its dates the Romanian way in an English interface states both, and a date filter's summary reads "After 24 Nov 2026" where the locale alone writes "After 24 nov. 2026": the day's order and digits are the locale's, its month's word the language's. A group's heading by day, week or month reads the same way: "November 2026", "24 Nov 2026", "Week of 24 Nov 2026". Unstated, it is `locale`, and `.with({ locale })` moves it along until you state one.
105
+ The language is a BCP 47 tag too: the language your interface reads in. The names the library writes from data are in it, a place's country and region, and so is the month's word in a date filter's summary and in a date group's heading, and the Date editor's month and weekday names (`CONTROLS.DateBody`, which also reads a month typed in it in this language), while dates' order and digits, numbers and the order text sorts in keep `locale`. So an app that writes its dates the Romanian way in an English interface states both, and a date filter's summary reads "After 24 Nov 2026" where the locale alone writes "After 24 nov. 2026": the day's order and digits are the locale's, its month's word the language's. A group's heading by day, week or month reads the same way: "November 2026", "24 Nov 2026", "Week of 24 Nov 2026". Unstated, it is `locale`, and `.with({ locale })` moves it along until you state one.
106
106
 
107
107
  ```ts
108
108
  import { countryName, locationShort } from "viewkitjs/fields";
@@ -183,6 +183,8 @@ function kept<Row extends { id: string }>(rows: readonly Row[], reader: ViewFiel
183
183
 
184
184
  A `FilterRule` is one field, one operator and one value. A `FilterGroup` combines its items with `and`, `or` or `not`, and groups nest. A `FilterTree` is the root: an `and` or an `or` over its rules and groups. `countMatching` says how many rows pass a tree.
185
185
 
186
+ Every negative way (`is_not`, `neq`, `is_none_of`, `not_contains`) keeps a row whose value is empty, for every type: "Amount is not 0" and "Stage is not Won" both keep the row that has neither. `is_empty` asks for those rows alone.
187
+
186
188
  ```ts
187
189
  const openOrBig: FilterTree = {
188
190
  op: "and",
@@ -388,7 +390,7 @@ assert.deepEqual(FILTER_OPERATORS.name, FILTER_OPERATORS.text);
388
390
 
389
391
  ## Number rules
390
392
 
391
- A number rule compares the number the cell draws. Equality rounds both sides to the column's decimals, two unless the reader's `decimalsOf` says otherwise, so `= 100` finds an amount that reads `100.00` after a conversion. The decimals the grid rounds a field to are `ruleDecimalsOf(field)`'s; a reader of your own, or a server that translates rules, hands those. The comparisons need no rounding. `between` takes its two bounds in either order. Zero is a value: only an absent number is empty.
393
+ A number rule compares the number the cell draws. Equality rounds both sides to the column's decimals, two unless the reader's `decimalsOf` says otherwise, so `= 100` finds an amount that reads `100.00` after a conversion. The decimals the grid rounds a field to are `ruleDecimalsOf(field)`'s; a reader of your own, or a server that translates rules, hands those. The comparisons need no rounding. `between` takes its two bounds in either order. Zero is a value: only an absent number is empty. `neq` keeps the rows with no number, as every "not" rule keeps an empty value.
392
394
 
393
395
  ```ts
394
396
  assert.deepEqual(kept(DEALS, deals, { fieldKey: "value", operator: "eq", value: 100 }), ["d5"]);
@@ -398,6 +400,7 @@ assert.equal(countMatching(DEALS, treeOf({ fieldKey: "value", operator: "eq", va
398
400
  assert.deepEqual(kept(DEALS, deals, { fieldKey: "value", operator: "between", value: [20000, 1000] }), ["d1", "d2"]);
399
401
  assert.deepEqual(kept(DEALS, deals, { fieldKey: "value", operator: "lt", value: 1000 }), ["d3", "d5"]);
400
402
  assert.deepEqual(kept(DEALS, deals, { fieldKey: "value", operator: "is_empty", value: null }), ["d6"]);
403
+ assert.ok(kept(DEALS, deals, { fieldKey: "value", operator: "neq", value: 100 }).includes("d6"));
401
404
  ```
402
405
 
403
406
  A rule over a currency column compares the number alone: `lt 1000` above keeps 900 EUR and the 99.996 whose code nobody states alike. A reader that converts its amounts into one currency makes the number comparable, and says so through `codeOf` (see [A currency column of mixed codes](#a-currency-column-of-mixed-codes)).
@@ -1025,7 +1028,7 @@ assert.deepEqual(broken.change, {});
1025
1028
 
1026
1029
  ## Folding and collation
1027
1030
 
1028
- Every text rule folds both sides the same way before it compares them: `foldText` decomposes the text, drops the Latin combining marks and lowercases it. Ș with a comma below, Ş with a cedilla and a plain S all fold to `s`. Only the Combining Diacritical Marks block is dropped, so the vowel signs of scripts where they are letters stay.
1031
+ Every text rule and every search folds both sides the same way before it compares them: `foldText` decomposes the text by compatibility (NFKD), drops the Latin combining marks, lowercases it, and maps the letters that have no combining form to their plain spelling: ł to l, ø to o, đ and ð to d, ı to i, ß to ss, æ to ae, œ to oe, þ to th. Ș with a comma below, Ş with a cedilla and a plain S all fold to `s`; a fullwidth letter, a ligature and a superscript read as their plain letters, so "2" finds "m²". Only the Combining Diacritical Marks block is dropped, so the vowel signs of scripts where they are letters stay. `viewkitjs/postgres` folds by the same rule in SQL.
1029
1032
 
1030
1033
  ```ts
1031
1034
  import { foldText } from "viewkitjs/fields/query";
@@ -1033,6 +1036,9 @@ import { foldText } from "viewkitjs/fields/query";
1033
1036
  assert.equal(foldText("Ștefan"), "stefan");
1034
1037
  assert.equal(foldText("Şerban"), "serban");
1035
1038
  assert.equal(foldText("Café"), "cafe");
1039
+ assert.equal(foldText("Łódź"), "lodz");
1040
+ assert.equal(foldText("Straße"), "strasse");
1041
+ assert.equal(foldText("ACME"), "acme");
1036
1042
  assert.equal(foldText("हिंदी"), "हिंदी".normalize("NFD"));
1037
1043
  ```
1038
1044
 
@@ -49,7 +49,7 @@ Guide: [the index](../guides/the-index.md).
49
49
 
50
50
  Guide: [conventions](../guides/conventions.md).
51
51
 
52
- - `defineConventions` — builds a host's frozen conventions: its locale, its names language (`language`, the language a place's country and region are named in, and the month of a date filter's summary and of a date group's heading; default its locale), time zone, decimal separator, region, id formats, message resolver and link platforms. It throws `FieldConventionsError` on a locale, zone, region or platform it cannot use, and the result's `with` returns a new copy with some of them stated differently.
52
+ - `defineConventions` — builds a host's frozen conventions: its locale, its names language (`language`, the language a place's country and region are named in, the month of a date filter's summary and of a date group's heading, and the Date editor's month and weekday names; default its locale), time zone, decimal separator, region, id formats, message resolver and link platforms. It throws `FieldConventionsError` on a locale, zone, region or platform it cannot use, and the result's `with` returns a new copy with some of them stated differently.
53
53
  - `DEFAULT_CONVENTIONS` — the conventions a function uses when it is handed none: `en-GB`, UTC, both decimal styles read, no region and the neutral English messages. They never depend on the runtime, so a server and a browser that state nothing agree.
54
54
  - `ConventionsInput` — what a host may state to `defineConventions`; every member is optional.
55
55
  - `ConventionsOverrides` — what `with` takes: any member of `ConventionsInput`, and `null` for `decimal` or `region` to state none.
@@ -27,10 +27,10 @@ Guide: [queries](../guides/queries.md), for every section on this page.
27
27
  - `whereWaits` — says whether a relation rule's where holds rules, none of which could narrow yet (each still being typed, set aside, or a group of those), read without types. Such a relation rule is still being typed and filters nothing; a where with no rules doesn't wait ("any" keeps the rows with at least one related record, "none" those with none).
28
28
  - `matchesRule` — judges one value against one rule by the value's type. An inactive rule matches everything; for several values a rule holds when some value matches, and a refusing rule when every value does.
29
29
  - `matchesTree` — judges one row against a tree through a reader of its fields, or a record reader that also hands in the records its relations hold. A node with no opinion (an unknown field, a rule still being typed, a rule across a relation whose records were not handed in) is dropped before its group combines, and a tree with no opinion matches.
30
- - `RuleReader` — what `matchesTree` reads a row through: for a rule, the field's value type, its value and its displayed decimals, or undefined when the field is unknown and the rule is skipped.
30
+ - `RuleReader` — what `matchesTree` reads a row through: for a rule, the field's value type, its value, its displayed decimals and whether it keeps decimal text (`exact`), or undefined when the field is unknown and the rule is skipped.
31
31
  - `RecordReader` — one record as a tree reads it: a reader of its fields, and optionally the records its relations hold.
32
32
  - `RelatedReader` — the records a relation holds, each a record reader of its own, for a rule across it; undefined when they are not handed in.
33
- - `MatchOptions` — the options a match takes: the column's displayed decimals, the moment that counts as now, and the conventions whose time zone places an instant on a day (UTC when unstated).
33
+ - `MatchOptions` — the options a match takes: the column's displayed decimals, the moment that counts as now, the conventions whose time zone places an instant on a day (UTC when unstated), and `exact`, when the field keeps decimal text and a number rule compares it exactly.
34
34
  - `emptyTree` — a new filter tree with no items, combined with `and`.
35
35
  - `isFilterGroup` — says whether a node is a group.
36
36
  - `isRelationRule` — says whether a node is a rule across a relation.
@@ -62,7 +62,7 @@ Guide: [queries](../guides/queries.md), for every section on this page.
62
62
  - `numberFilterOperatorLabel` — a number operator's name in the host's words.
63
63
  - `isNumberRuleActive` — says whether a number rule is complete enough to filter; a half-typed between is not.
64
64
  - `numberRuleLabel` — a number rule's summary, such as `> 100` or `100 – 500`, at the column's decimals and with its unit.
65
- - `matchesNumberRule` — judges a value against a number rule: equality rounds both sides to the column's displayed decimals, and zero is a value, never empty. Decimal text is read as the number it is.
65
+ - `matchesNumberRule` — judges a value against a number rule: equality rounds both sides to the column's displayed decimals, zero is a value, never empty, and `neq` keeps an empty value. Text is read as the number it spells; with `exact`, for a field that keeps decimal text, its canonical text is compared exactly, as digits.
66
66
  - `ruleDecimalsOf` — the decimals a number rule's `eq` and `neq` round to on a field, as the grid works them out for its column: none for a whole number, percent, currency or range, else the decimals the field states (a rollup, formula or lookup read as the field it shows), else 0 for a percent and 2 for any other; on a range, either end's, as its cell draws it: none when whole, else the decimals it states, else 0 for a percent range and 2 for any other. Hand it as `matchesRule`'s `decimals` (or a reader's `decimalsOf`), and round at it in a query that translates rules, so a list filtered there keeps the rows the grid keeps.
67
67
  - `parseDurationInput` — reads a typed duration (`500ms`, `90s`, `2m 30s`, `1h30m`) into milliseconds; a bare number is seconds, and anything it cannot read whole is null.
68
68
  - `formatDurationInput` — writes milliseconds as `parseDurationInput` reads them back exactly, keeping every millisecond and dropping only the zero units, in the host's decimal separator.
@@ -293,4 +293,5 @@ A link's platform is read through `matchesRule` with the part `platform`, from t
293
293
 
294
294
  ## Folding and collation
295
295
 
296
- - `foldText` — folds text for comparison: decomposes it, drops the Latin combining marks and lowercases it, so every text rule ignores case and diacritics. Sorts and bucket names collate in the host's locale instead.
296
+ - `foldText` — folds text for comparison: decomposes it by compatibility (NFKD), drops the Latin combining marks, lowercases it and maps ł, ø, đ, ð, ı, ß, æ, œ and þ to their plain spelling, so every text rule and search ignores case and diacritics.
297
+ - `FOLDED_LETTERS` — the letters with no combining form that `foldText` maps, lowercase, and their plain spelling; `viewkitjs/postgres` folds by the same table. Sorts and bucket names collate in the host's locale instead.
@@ -241,7 +241,7 @@ The row then holds canonical decimal TEXT, which is what an ORM hands back for s
241
241
 
242
242
  An editor still commits a NUMBER, and `acceptFieldCommit` still takes one: it judges that number's own digits, which is why a commit of `82.355` to a `decimals: 2` field is refused rather than rounded into passing. The same gate catches a COMPUTED figure's float noise the same way — `0.1 + 0.2`'s shortest text is `0.30000000000000004`, which a `decimals: 2` field refuses just as it refuses `82.355`, where a number-storage field tolerates that noise on purpose. Round a computed figure to the field's scale before committing it (`Number(n.toFixed(2))`), or write the stored text directly with `decimalTextOf(n, 2)` on the binding side. Your binding is what writes the row, with `decimalTextOf(n)` — the shortest text that round-trips, never an exponent — or `decimalTextOf(n, 2)` to match a `numeric(12,2)` column exactly. `numberOfDecimalText(text)` is the inverse, for drawing and for arithmetic you do yourself. `optimisticDisplay` answers the text, so your overlay is already the shape the refetch brings. Ask `storesDecimalText(field)` rather than reading `storage` yourself.
243
243
 
244
- One limit, stated rather than solved: the query layer compares what the cell draws, as a number, so a filter, a sort or a group on such a column is lossy past 2^53 — two texts that differ only that far out read as the same double. The exact digits are kept by the column and by both acceptance gates, which compare the text itself. The library still does no arithmetic on money: it compares two texts, and it never adds them.
244
+ A filter and a sort on such a column compare its text exactly, as digits, past 2^53 too, and a database answers the same: `matchesRule` is told the field keeps decimal text (`MatchOptions.exact`, which `evaluateView`'s reader sets from `storesDecimalText`), and its "is" rounds half away from zero. One limit, stated rather than solved: a group and a figure on such a column still read it as a number, so they are lossy past 2^53 — two texts that differ only that far out read as the same double. The exact digits are kept by the column and by both acceptance gates, which compare the text itself. The library still does no arithmetic on money: it compares two texts, and it never adds them.
245
245
 
246
246
  ## State your conventions once
247
247
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "viewkitjs",
3
- "version": "0.25.0",
3
+ "version": "0.26.0-pr-770-2abf987",
4
4
  "description": "ViewKit — typed fields, the grid and its editors, and a list's SQL for record lists, in one package: viewkitjs/fields, viewkitjs/views and viewkitjs/postgres. By Sheaf.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -202,6 +202,7 @@
202
202
  "access": "public"
203
203
  },
204
204
  "dependencies": {
205
+ "country-flag-icons": "1.6.20",
205
206
  "libphonenumber-js": "1.13.15",
206
207
  "tldts": "7.5.5"
207
208
  },
@@ -1,14 +1,23 @@
1
+ import { FOLDED_LETTERS } from "viewkitjs/fields/query";
1
2
  import { sql } from "./sql.js";
2
3
  const JS_TRIM = "\t\n\u000b\f\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff";
3
4
  const ASCII_TRIM = "\t\n\u000b\f\r ";
4
5
  const MARKS = "[\\u0300-\\u036f]";
6
+ const LETTER_PAIRS = Object.entries(FOLDED_LETTERS);
7
+ const ONE_FROM = LETTER_PAIRS.filter(([, to]) => to.length === 1).map(([from]) => from).join("");
8
+ const ONE_TO = LETTER_PAIRS.filter(([, to]) => to.length === 1).map(([, to]) => to).join("");
9
+ const TWO = LETTER_PAIRS.filter(([, to]) => to.length > 1);
10
+ function lettersMapped(lowered) {
11
+ return TWO.reduce((text, [from, to]) => sql `replace(${text}, ${from}::text, ${to}::text)`, sql `translate(${lowered}, ${ONE_FROM}::text, ${ONE_TO}::text)`);
12
+ }
5
13
  const orEmpty = (text) => sql `COALESCE(${text}, '')`;
6
14
  export function trimmedSql(text) {
7
15
  return sql `btrim(${orEmpty(text)}, ${JS_TRIM}::text)`;
8
16
  }
9
17
  export function foldedSql(text) {
10
18
  const c = orEmpty(text);
11
- return sql `(CASE WHEN octet_length(${c}) = char_length(${c}) THEN lower(btrim(${c}, ${ASCII_TRIM}::text) COLLATE "C") ELSE (lower(regexp_replace(normalize(btrim(${c}, ${JS_TRIM}::text), NFD), ${MARKS}::text, '', 'g') COLLATE "und-x-icu") COLLATE "C") END)`;
19
+ const lowered = sql `(lower(regexp_replace(normalize(btrim(${c}, ${JS_TRIM}::text), NFKD), ${MARKS}::text, '', 'g') COLLATE "und-x-icu") COLLATE "C")`;
20
+ return sql `(CASE WHEN octet_length(${c}) = char_length(${c}) THEN lower(btrim(${c}, ${ASCII_TRIM}::text) COLLATE "C") ELSE (${lettersMapped(lowered)} COLLATE "C") END)`;
12
21
  }
13
22
  export function containsPattern(word) {
14
23
  return `%${word.replace(/[\\%_]/g, (character) => `\\${character}`)}%`;
@@ -1,4 +1,4 @@
1
- import { conversionOf, defineConventions, } from "viewkitjs/fields";
1
+ import { conversionOf, decimalTextOf, defineConventions, storesDecimalText, } from "viewkitjs/fields";
2
2
  import { dateFilterRuleOf, foldText, resolveRelativeWindow, ruleDecimalsOf, } from "viewkitjs/fields/query";
3
3
  import { dayAfter, dayStart, DOUBLE_OVERFLOW, DOUBLE_UNDERFLOW, roundedBand } from "./bounds.js";
4
4
  import { foldedContainsSql, foldedSql, trimmedSql } from "./fold.js";
@@ -83,8 +83,36 @@ function numberOf(value) {
83
83
  throw new Error("ruleSql: an active rule's number is missing");
84
84
  return value;
85
85
  }
86
+ function decimalSql(checked, value) {
87
+ const { rule, def } = checked;
88
+ const x = sql `NULLIF(NULLIF(NULLIF(${value}, 'NaN'::numeric), 'Infinity'::numeric), '-Infinity'::numeric)`;
89
+ const bound = (n) => sql `${decimalTextOf(n)}::numeric`;
90
+ const operator = rule.operator;
91
+ if (operator === "is_empty")
92
+ return sql `${x} IS NULL`;
93
+ if (operator === "is_not_empty")
94
+ return sql `${x} IS NOT NULL`;
95
+ if (operator === "between") {
96
+ const [low, high] = numbersOf(rule.value).sort((a, b) => a - b);
97
+ if (low === undefined || high === undefined)
98
+ throw new Error("ruleSql: between takes two numbers");
99
+ return sql `${x} IS NOT NULL AND ${x} BETWEEN ${bound(low)} AND ${bound(high)}`;
100
+ }
101
+ const target = numberOf(rule.value);
102
+ if (operator === "eq" || operator === "neq") {
103
+ const digits = sql `${String(decimalsOf(def))}::int`;
104
+ const same = sql `round(${x}, ${digits}) = round(${bound(target)}, ${digits})`;
105
+ return operator === "eq" ? sql `${x} IS NOT NULL AND ${paren(same)}` : sql `${x} IS NULL OR ${not(same)}`;
106
+ }
107
+ const compare = NUMBER_COMPARES[operator];
108
+ if (compare === undefined)
109
+ throw new Error(`ruleSql: ${operator} is no number operator`);
110
+ return sql `${x} IS NOT NULL AND ${x} ${compare} ${bound(target)}`;
111
+ }
86
112
  function numberSql(checked, value) {
87
113
  const { rule, stored, def } = checked;
114
+ if (stored === "numeric" && storesDecimalText(def))
115
+ return decimalSql(checked, value);
88
116
  const x = numberValue(value, stored);
89
117
  const cast = boundCast(stored);
90
118
  const bound = (n) => sql `${String(n)}${cast}`;
@@ -103,7 +131,7 @@ function numberSql(checked, value) {
103
131
  if (operator === "eq" || operator === "neq") {
104
132
  const [low, high] = roundedBand(target, decimalsOf(def));
105
133
  const band = sql `${x} BETWEEN ${bound(low)} AND ${bound(high)}`;
106
- return sql `${x} IS NOT NULL AND ${operator === "eq" ? paren(band) : not(band)}`;
134
+ return operator === "eq" ? sql `${x} IS NOT NULL AND ${paren(band)}` : sql `${x} IS NULL OR ${not(band)}`;
107
135
  }
108
136
  const compare = NUMBER_COMPARES[operator];
109
137
  if (compare === undefined)
@@ -98,7 +98,7 @@ function wordOf(scope, read, fenced) {
98
98
  const row = readableField(scope, read.at.table, read.key).mapping.row;
99
99
  return (word) => rowProbeOn(scope, read.at, read.key, (probe) => phoneRuleSql(phoneOnRow(probe, row, read.key), { fieldKey: read.key, operator: "contains", value: word }, undefined), fenced);
100
100
  }
101
- return (word) => rowProbeSql(scope, read.at, read.key, (value) => (read.option ? optionWord(read.def, value)(word) : foldedContainsSql(value, word)), fenced);
101
+ return (word) => rowProbeSql(scope, read.at, read.key, (value) => (read.option ? optionWord(read.def, value)(word) : foldedContainsSql(value, word)), fenced, !read.option && [...word].length >= TRIGRAM);
102
102
  case "relation":
103
103
  return (word) => namedBy(scope, read.own, read.to, word);
104
104
  case "lead":