viewkitjs 0.24.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.
- package/CHANGELOG.md +20 -0
- package/fields/dist/creatable.d.ts +9 -5
- package/fields/dist/creatable.js +8 -1
- package/fields/dist/messages.d.ts +57 -1
- package/fields/dist/messages.js +104 -0
- package/fields/dist/parse-number.d.ts +9 -0
- package/fields/dist/parse-number.js +23 -0
- package/fields/dist/query/exact-number.d.ts +5 -0
- package/fields/dist/query/exact-number.js +18 -0
- package/fields/dist/query/filter.d.ts +3 -0
- package/fields/dist/query/filter.js +2 -1
- package/fields/dist/query/fold.d.ts +2 -0
- package/fields/dist/query/fold.js +17 -1
- package/fields/dist/query/number.d.ts +8 -7
- package/fields/dist/query/number.js +30 -3
- package/fields/dist/query/read-rule.js +2 -1
- package/fields/dist/query/sort.js +17 -2
- package/fields/dist/registry.js +4 -7
- package/fields/dist/testing/cases.js +8 -0
- package/fields/dist/testing/samples.js +1 -0
- package/fields/dist/types.d.ts +4 -2
- package/fields/dist/zod.d.ts +58 -0
- package/fields/dist/zod.js +430 -2
- package/fields/docs/guides/checking-definitions.md +6 -1
- package/fields/docs/guides/conventions.md +1 -1
- package/fields/docs/guides/field-types.md +5 -1
- package/fields/docs/guides/queries.md +8 -2
- package/fields/docs/reference/definitions.md +1 -2
- package/fields/docs/reference/fields.md +1 -1
- package/fields/docs/reference/query.md +5 -4
- package/fields/docs/reference/types.md +2 -1
- package/fields/skills/viewkit/SKILL.md +3 -3
- package/package.json +2 -1
- package/postgres/dist/fold.js +10 -1
- package/postgres/dist/rules.js +30 -2
- package/postgres/dist/search.js +1 -1
- package/postgres/dist/value-rows.d.ts +15 -7
- package/postgres/dist/value-rows.js +30 -6
- package/postgres/docs/guides/field-map.md +3 -3
- package/views/dist/contract.d.ts +63 -1
- package/views/dist/contract.js +63 -0
- package/views/dist/controls/avatar/avatar.d.ts +58 -0
- package/views/dist/controls/avatar/avatar.js +54 -0
- package/views/dist/controls/avatar/looks.d.ts +4 -0
- package/views/dist/controls/avatar/looks.js +5 -0
- package/views/dist/controls/avatar/tokens.d.ts +131 -0
- package/views/dist/controls/avatar/tokens.js +35 -0
- package/views/dist/controls/avatar.css +163 -0
- package/views/dist/controls/compound-editor/compound-editor.d.ts +88 -0
- package/views/dist/controls/compound-editor/compound-editor.js +35 -0
- package/views/dist/controls/compound-editor/keeping.d.ts +13 -0
- package/views/dist/controls/compound-editor/keeping.js +56 -0
- package/views/dist/controls/compound-editor/looks.d.ts +15 -0
- package/views/dist/controls/compound-editor/looks.js +18 -0
- package/views/dist/controls/compound-editor/map-parts-body.d.ts +15 -0
- package/views/dist/controls/compound-editor/map-parts-body.js +28 -0
- package/views/dist/controls/compound-editor/name-parts.d.ts +3 -0
- package/views/dist/controls/compound-editor/name-parts.js +100 -0
- package/views/dist/controls/compound-editor/name.d.ts +18 -0
- package/views/dist/controls/compound-editor/name.js +20 -0
- package/views/dist/controls/compound-editor/place-parts.d.ts +3 -0
- package/views/dist/controls/compound-editor/place-parts.js +220 -0
- package/views/dist/controls/compound-editor/place.d.ts +58 -0
- package/views/dist/controls/compound-editor/place.js +79 -0
- package/views/dist/controls/compound-editor/range-parts.d.ts +3 -0
- package/views/dist/controls/compound-editor/range-parts.js +117 -0
- package/views/dist/controls/compound-editor/range.d.ts +7 -0
- package/views/dist/controls/compound-editor/range.js +11 -0
- package/views/dist/controls/compound-editor/row.d.ts +15 -0
- package/views/dist/controls/compound-editor/row.js +12 -0
- package/views/dist/controls/compound-editor/shell.d.ts +18 -0
- package/views/dist/controls/compound-editor/shell.js +17 -0
- package/views/dist/controls/compound-editor/tokens.d.ts +48 -0
- package/views/dist/controls/compound-editor/tokens.js +14 -0
- package/views/dist/controls/compound-editor.css +79 -0
- package/views/dist/controls/controls.d.ts +14 -0
- package/views/dist/controls/controls.js +14 -0
- package/views/dist/controls/date-editor/calendar.d.ts +60 -0
- package/views/dist/controls/date-editor/calendar.js +132 -0
- package/views/dist/controls/date-editor/date-days.d.ts +25 -0
- package/views/dist/controls/date-editor/date-days.js +24 -0
- package/views/dist/controls/date-editor/date-editor.d.ts +64 -0
- package/views/dist/controls/date-editor/date-editor.js +300 -0
- package/views/dist/controls/date-editor/date-parts.d.ts +21 -0
- package/views/dist/controls/date-editor/date-parts.js +101 -0
- package/views/dist/controls/date-editor/looks.d.ts +21 -0
- package/views/dist/controls/date-editor/looks.js +22 -0
- package/views/dist/controls/date-editor/map-calendar.d.ts +2 -0
- package/views/dist/controls/date-editor/map-calendar.js +38 -0
- package/views/dist/controls/date-editor/map-date-body.d.ts +11 -0
- package/views/dist/controls/date-editor/map-date-body.js +38 -0
- package/views/dist/controls/date-editor/segments.d.ts +33 -0
- package/views/dist/controls/date-editor/segments.js +54 -0
- package/views/dist/controls/date-editor/tokens.d.ts +143 -0
- package/views/dist/controls/date-editor/tokens.js +38 -0
- package/views/dist/controls/date-editor/words.d.ts +32 -0
- package/views/dist/controls/date-editor/words.js +26 -0
- package/views/dist/controls/date-editor.css +197 -0
- package/views/dist/controls/field/field.d.ts +2 -1
- package/views/dist/controls/field/field.js +3 -2
- package/views/dist/controls/field.css +3 -9
- package/views/dist/controls/flag/flag.d.ts +6 -0
- package/views/dist/controls/flag/flag.js +21 -0
- package/views/dist/controls/flag/tokens.d.ts +23 -0
- package/views/dist/controls/flag/tokens.js +8 -0
- package/views/dist/controls/flag.css +13 -0
- package/views/dist/controls/index.d.ts +30 -0
- package/views/dist/controls/index.js +29 -0
- package/views/dist/controls/inline-input/inline-input.js +3 -1
- package/views/dist/controls/inline-input.css +1 -2
- package/views/dist/controls/input/input.d.ts +1 -1
- package/views/dist/controls/input/input.js +6 -4
- package/views/dist/controls/input.css +19 -48
- package/views/dist/controls/internal/phone.d.ts +23 -0
- package/views/dist/controls/internal/phone.js +25 -0
- package/views/dist/controls/internal/read-token.d.ts +2 -1
- package/views/dist/controls/internal/read-token.js +1 -1
- package/views/dist/controls/internal/scroll.d.ts +38 -0
- package/views/dist/controls/internal/scroll.js +126 -0
- package/views/dist/controls/internal/shell-hand.d.ts +6 -0
- package/views/dist/controls/internal/shell-hand.js +34 -0
- package/views/dist/controls/internal/shell.d.ts +7 -0
- package/views/dist/controls/internal/shell.js +4 -0
- package/views/dist/controls/internal/told-step.d.ts +14 -0
- package/views/dist/controls/internal/told-step.js +12 -0
- package/views/dist/controls/list/looks.d.ts +4 -0
- package/views/dist/controls/list/looks.js +12 -0
- package/views/dist/controls/list.css +19 -21
- package/views/dist/controls/menu/map-menu.d.ts +11 -0
- package/views/dist/controls/menu/map-menu.js +47 -0
- package/views/dist/controls/menu/menu.d.ts +75 -0
- package/views/dist/controls/menu/menu.js +105 -0
- package/views/dist/controls/menu/tokens.d.ts +23 -0
- package/views/dist/controls/menu/tokens.js +8 -0
- package/views/dist/controls/menu-list/looks.d.ts +5 -1
- package/views/dist/controls/menu-list/looks.js +6 -4
- package/views/dist/controls/menu-list/menu-list.js +10 -7
- package/views/dist/controls/menu-list.css +39 -31
- package/views/dist/controls/menu.css +25 -0
- package/views/dist/controls/number-field/number-field.js +4 -3
- package/views/dist/controls/number-field.css +2 -8
- package/views/dist/controls/picker/looks.d.ts +19 -0
- package/views/dist/controls/picker/looks.js +31 -0
- package/views/dist/controls/picker/map-fields-body.d.ts +18 -0
- package/views/dist/controls/picker/map-fields-body.js +43 -0
- package/views/dist/controls/picker/map-picker.d.ts +27 -0
- package/views/dist/controls/picker/map-picker.js +71 -0
- package/views/dist/controls/picker/picker.d.ts +193 -0
- package/views/dist/controls/picker/picker.js +801 -0
- package/views/dist/controls/picker/rows.d.ts +129 -0
- package/views/dist/controls/picker/rows.js +90 -0
- package/views/dist/controls/picker/tokens.d.ts +147 -0
- package/views/dist/controls/picker/tokens.js +39 -0
- package/views/dist/controls/picker.css +241 -0
- package/views/dist/controls/popover/popover.js +3 -2
- package/views/dist/controls/popup-line/tokens.d.ts +23 -0
- package/views/dist/controls/popup-line/tokens.js +8 -0
- package/views/dist/controls/popup-line.css +44 -0
- package/views/dist/controls/select/filled.d.ts +7 -0
- package/views/dist/controls/select/filled.js +5 -0
- package/views/dist/controls/select/fit.d.ts +9 -0
- package/views/dist/controls/select/fit.js +11 -0
- package/views/dist/controls/select/select.d.ts +131 -0
- package/views/dist/controls/select/select.js +229 -0
- package/views/dist/controls/select/side.d.ts +3 -0
- package/views/dist/controls/select/side.js +4 -0
- package/views/dist/controls/select/tokens.d.ts +27 -0
- package/views/dist/controls/select/tokens.js +9 -0
- package/views/dist/controls/select.css +89 -0
- package/views/dist/controls/switch/switch.js +3 -1
- package/views/dist/controls/switch.css +5 -15
- package/views/dist/controls/text-editor/check.d.ts +42 -0
- package/views/dist/controls/text-editor/check.js +50 -0
- package/views/dist/controls/text-editor/countries.d.ts +7 -0
- package/views/dist/controls/text-editor/countries.js +11 -0
- package/views/dist/controls/text-editor/looks.d.ts +14 -0
- package/views/dist/controls/text-editor/looks.js +17 -0
- package/views/dist/controls/text-editor/map-text-body.d.ts +6 -0
- package/views/dist/controls/text-editor/map-text-body.js +13 -0
- package/views/dist/controls/text-editor/phone-number.d.ts +32 -0
- package/views/dist/controls/text-editor/phone-number.js +72 -0
- package/views/dist/controls/text-editor/text-editor.d.ts +50 -0
- package/views/dist/controls/text-editor/text-editor.js +275 -0
- package/views/dist/controls/text-editor/tokens.d.ts +63 -0
- package/views/dist/controls/text-editor/tokens.js +18 -0
- package/views/dist/controls/text-editor.css +83 -0
- package/views/dist/controls/tokens.js +18 -0
- package/views/dist/editors/DateEditor.js +3 -1
- package/views/dist/editors/SelectEditor.js +1 -1
- package/views/dist/internal/phone-line.d.ts +5 -0
- package/views/dist/internal/phone-line.js +4 -0
- package/views/dist/looks/index.d.ts +7 -0
- package/views/dist/looks/index.js +7 -0
- package/views/dist/looks/pieces.js +12 -0
- package/views/dist/model/column-filters.js +3 -2
- package/views/dist/provider/ViewsProvider.js +2 -2
- package/views/dist/provider/components.d.ts +4 -0
- package/views/dist/provider/desktop.d.ts +2 -2
- package/views/dist/provider/desktop.js +1 -1
- package/views/dist/provider/missing-slot.d.ts +1 -1
- package/views/dist/provider/missing-slot.js +1 -1
- package/views/dist/styles.css +949 -158
- package/views/dist/styles.unlayered.css +949 -158
- package/views/docs/contract.md +8 -7
- package/views/docs/controls/avatar.md +38 -0
- package/views/docs/controls/compound-editor.md +19 -0
- package/views/docs/controls/date-editor.md +43 -0
- package/views/docs/controls/flag.md +13 -0
- package/views/docs/controls/menu.md +11 -0
- package/views/docs/controls/picker.md +42 -0
- package/views/docs/controls/popup-line.md +11 -0
- package/views/docs/controls/select.md +12 -0
- package/views/docs/controls/text-editor.md +23 -0
- package/views/docs/reference/controls.md +230 -1
- package/views/docs/reference/editors-date.md +1 -1
- package/views/docs/reference/looks.md +17 -0
- package/views/docs/reference/react.md +5 -5
- package/views/docs/reference/views.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,26 @@ Until 0.19.0 ViewKit shipped as three packages; their changes are in [fields/CHA
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [0.25.0] — 2026-11-26
|
|
9
|
+
|
|
10
|
+
viewkitjs/views/controls: the Menu (the components map's default `Menu`, with `menuEntries`), its context menu and its ⋯, the Avatar and its stack, the Select, and the Picker's core (`usePicker`, `Picker`, `PickerUnder` and its rows), with the popup line's stylesheet, the phone's line (`usePhone`, `PhoneHost`, `ComputerHost`) and a list's own scrolling; their looks (`LIST_LOOKS`, `PICKER_LOOKS`, `AVATAR_LOOKS`) in viewkitjs/views/looks.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `viewkitjs/fields/definitions`: every setting `creatableFieldTypes(cv)` lists carries a `label` in the host's words, and a word or words setting carries `wordLabels`, a name for each of its words, so a New field dialog names every setting and choice without a copy of its own.
|
|
15
|
+
- Two message keys, so a host renames them in its own language; an exhaustive resolver words them:
|
|
16
|
+
- `setting.label` (values `type`, `path`): Default value, Fewest characters, Most characters (a name's and a place's: Most characters in each part), Pattern it must match, Written over several lines, Stored as, Lowest value, Highest value, Whole numbers only, Most decimals, Shown as, Decimals shown, Unit after the number, Show + and −, A rise reads as, Stored in, Duration style, Currency, A range of, Per, A date to look forward to, Date style, Show the time, Options, Values allowed, Most values (a multi-select's: Most choices), Tidy each value, Links to, How many, Holds several values, Parts of the place.
|
|
17
|
+
- `setting.word` (values `type`, `path`, `word`): Number and Exact decimal; Number and Duration; Checkbox, Icon, Marker and Words; Up is good and Neutral; Milliseconds and Seconds; Adaptive, Clock and Units; Number, Bar and Ring; Numbers, Amounts and Percents; Hour, Day, Week, Month and Year; Short, Long, Numbers only and Relative; Only the listed options and Any value typed in; Trim spaces, Lowercase and Spaces to hyphens; One record and Several records; Address line 1, Address line 2, Postal code, City, Region, Region code and Country.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- `viewkitjs/fields`: a text field's `validation.pattern` is read in ViewKit's own pattern dialect and matched without backtracking: each character of a value costs at most one pass over the pattern's steps, and one value may cost at most 20,000,000 steps in all (its characters times the pattern's steps, about a fifth of a second). The dialect is JavaScript's regular-expression syntax with no flags and answers as `RegExp` does, without lookahead, lookbehind, backreferences or group flags (`(?i:…)`), and without the legacy forms whose meaning depends on where they sit (a lone `{`, `}` or `]`); its escapes are `\d \w \s \b`, their capitals, `\t \n \r \f \v \0 \xHH \uHHHH` and any escaped ASCII symbol, and an escaped letter or digit it doesn't know (`\q`, `\cJ`, `\u{41}`) is refused. A pattern is at most 500 characters and 1,000 steps once its repeats are counted out. `checkFieldSpec`, `defineFields` and `zodFor` refuse a pattern outside it, in the same words. Before, any pattern that compiled was taken: a pattern declared in code that uses one of these now fails at definition and is rewritten, for example `"^(?!test)\\w+$"` (lookahead) as a check of its own, `"(\\w)\\1"` (a backreference) as a check of its own, `"a{"` as `"a\\{"`, `"\\q"` as `"q"`. A definition already stored as data is checked the same way when `zodFor` builds its schema: run `checkFieldSpec` over your stored definitions before you upgrade.
|
|
22
|
+
- `viewkitjs/fields`: `zodFor` refuses a value too long for its field's pattern to read within that cost as too long ("Too long — at most N characters", `validation.max-length`), before the pattern reads it: 20,000 characters for a cap-sized pattern of 1,000 steps, far more for a short one. A field's own `maxLength`, when lower, says the limit as before.
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- `viewkitjs/fields`: a pattern such as `(a+)+$`, accepted from data by `checkFieldSpec`, no longer lets one crafted value hold a server's thread: no pattern and no value cost more than the bound above.
|
|
27
|
+
|
|
8
28
|
## [0.24.0] — 2026-11-26
|
|
9
29
|
|
|
10
30
|
viewkitjs/views/controls: the menu list, the list's stylesheet and the helpers they stand on (Icon, Grip, useHoldDrag, useReorder); the menu list's looks in viewkitjs/views/looks. A piece's looks may pick fewer options than it has (`PieceLooks<Id, Picked>`).
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { type FieldConventions } from "./conventions.js";
|
|
2
2
|
import type { CategoryColor } from "./design/category-colors.js";
|
|
3
3
|
import type { StatusSlot } from "./design/status-slots.js";
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
export type CreatableFieldType = Exclude<FieldType, "actor" | "lookup" | "rollup" | "formula">;
|
|
4
|
+
import type { CreatableFieldType, FieldSpec } from "./types.js";
|
|
5
|
+
export type { CreatableFieldType } from "./types.js";
|
|
7
6
|
/** A setting applies only while another word or switch setting holds `is`; absent, that setting reads as its
|
|
8
7
|
* first word (a switch: off). When it stops holding, the setting is removed, and a block it leaves empty
|
|
9
8
|
* (`validation`, `format`, `code`) is removed with it: `checkFieldSpec` refuses the leftovers. */
|
|
@@ -16,6 +15,8 @@ export type FieldSettingWhen = {
|
|
|
16
15
|
type SettingBase = {
|
|
17
16
|
/** Where it sits in a definition, dotted: "validation.maxLength", "code.fixed". */
|
|
18
17
|
path: string;
|
|
18
|
+
/** Its name in the host's words, the message `setting.label`: "Decimals shown". */
|
|
19
|
+
label: string;
|
|
19
20
|
/** It holds a value whenever it applies: the starting definition carries one, or (a relation's kind) the app
|
|
20
21
|
* sets it before it saves. */
|
|
21
22
|
required?: true;
|
|
@@ -26,14 +27,18 @@ type SettingBase = {
|
|
|
26
27
|
/** One setting a definition of a type takes, with its kind and, for a word, its allowed words. */
|
|
27
28
|
export type FieldTypeSetting = SettingBase & ({
|
|
28
29
|
kind: "switch";
|
|
29
|
-
}
|
|
30
|
+
}
|
|
31
|
+
/** `wordLabels` names each word in the host's words, the message `setting.word`: "Up is good". */
|
|
32
|
+
| {
|
|
30
33
|
kind: "word";
|
|
31
34
|
words: readonly string[];
|
|
35
|
+
wordLabels: Readonly<Record<string, string>>;
|
|
32
36
|
}
|
|
33
37
|
/** Several of `words`, each once, in the person's order. */
|
|
34
38
|
| {
|
|
35
39
|
kind: "words";
|
|
36
40
|
words: readonly string[];
|
|
41
|
+
wordLabels: Readonly<Record<string, string>>;
|
|
37
42
|
} | {
|
|
38
43
|
kind: "number";
|
|
39
44
|
min?: number;
|
|
@@ -82,4 +87,3 @@ export declare const CREATABLE_FIELD_TYPES: readonly CreatableFieldType[];
|
|
|
82
87
|
* system sets, nor a lookup, rollup or formula, which are worked out from other fields.
|
|
83
88
|
*/
|
|
84
89
|
export declare function creatableFieldTypes(cv?: FieldConventions): readonly FieldTypeEntry[];
|
|
85
|
-
export {};
|
package/fields/dist/creatable.js
CHANGED
|
@@ -172,6 +172,13 @@ function deepFreeze(value) {
|
|
|
172
172
|
}
|
|
173
173
|
deepFreeze(ENTRIES);
|
|
174
174
|
export const CREATABLE_FIELD_TYPES = Object.freeze(ENTRIES.map((e) => e.type));
|
|
175
|
+
function labelled(type, setting, cv) {
|
|
176
|
+
const label = cv.messages({ key: "setting.label", values: { type, path: setting.path } });
|
|
177
|
+
if (setting.kind !== "word" && setting.kind !== "words")
|
|
178
|
+
return Object.freeze({ ...setting, label });
|
|
179
|
+
const wordLabels = Object.freeze(Object.fromEntries(setting.words.map((word) => [word, cv.messages({ key: "setting.word", values: { type, path: setting.path, word } })])));
|
|
180
|
+
return Object.freeze({ ...setting, label, wordLabels });
|
|
181
|
+
}
|
|
175
182
|
export function creatableFieldTypes(cv = DEFAULT_CONVENTIONS) {
|
|
176
183
|
cv = conventionsOr(cv);
|
|
177
184
|
return Object.freeze(ENTRIES.map(({ type, several, start, settings }) => {
|
|
@@ -181,7 +188,7 @@ export function creatableFieldTypes(cv = DEFAULT_CONVENTIONS) {
|
|
|
181
188
|
label,
|
|
182
189
|
icon: type,
|
|
183
190
|
several,
|
|
184
|
-
settings,
|
|
191
|
+
settings: Object.freeze(settings.map((setting) => labelled(type, setting, cv))),
|
|
185
192
|
spec: deepFreeze(JSON.parse(JSON.stringify({ type, label, ...start }))),
|
|
186
193
|
});
|
|
187
194
|
}));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ActorType, FieldType, RollupFn } from "./types.js";
|
|
1
|
+
import type { ActorType, CreatableFieldType, FieldType, RollupFn } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* A typed message plus the values its host may interpolate. EVERY sentence the
|
|
4
4
|
* library writes is one of these — a host that translates them translates the
|
|
@@ -69,6 +69,24 @@ export type FieldMessage = {
|
|
|
69
69
|
values: {
|
|
70
70
|
type: FieldType;
|
|
71
71
|
};
|
|
72
|
+
}
|
|
73
|
+
/** A setting a New field dialog offers (`creatableFieldTypes`), by where it sits in the type's definition:
|
|
74
|
+
* "Decimals shown" for `format.decimals`. */
|
|
75
|
+
| {
|
|
76
|
+
key: "setting.label";
|
|
77
|
+
values: {
|
|
78
|
+
type: CreatableFieldType;
|
|
79
|
+
path: string;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** One of the words a word or words setting offers: "Up is good" for `format.signedTone`'s `positive-good`. */
|
|
83
|
+
| {
|
|
84
|
+
key: "setting.word";
|
|
85
|
+
values: {
|
|
86
|
+
type: CreatableFieldType;
|
|
87
|
+
path: string;
|
|
88
|
+
word: string;
|
|
89
|
+
};
|
|
72
90
|
} | {
|
|
73
91
|
key: "field.cannot-empty";
|
|
74
92
|
} | {
|
|
@@ -134,6 +152,44 @@ export type FieldMessage = {
|
|
|
134
152
|
key: "time.placeholder";
|
|
135
153
|
} | {
|
|
136
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
|
+
};
|
|
137
193
|
} | {
|
|
138
194
|
key: "chips.add-placeholder";
|
|
139
195
|
} | {
|
package/fields/dist/messages.js
CHANGED
|
@@ -24,6 +24,75 @@ const TYPE_LABELS = {
|
|
|
24
24
|
rollup: "Rollup",
|
|
25
25
|
formula: "Formula",
|
|
26
26
|
};
|
|
27
|
+
const SETTING_LABELS = {
|
|
28
|
+
default: "Default value",
|
|
29
|
+
"validation.minLength": "Fewest characters",
|
|
30
|
+
"validation.maxLength": "Most characters",
|
|
31
|
+
"validation.pattern": "Pattern it must match",
|
|
32
|
+
"format.long": "Written over several lines",
|
|
33
|
+
storage: "Stored as",
|
|
34
|
+
"validation.min": "Lowest value",
|
|
35
|
+
"validation.max": "Highest value",
|
|
36
|
+
"validation.integer": "Whole numbers only",
|
|
37
|
+
"validation.decimals": "Most decimals",
|
|
38
|
+
"format.style": "Shown as",
|
|
39
|
+
"format.decimals": "Decimals shown",
|
|
40
|
+
"format.suffix": "Unit after the number",
|
|
41
|
+
"format.signed": "Show + and −",
|
|
42
|
+
"format.signedTone": "A rise reads as",
|
|
43
|
+
"format.unit": "Stored in",
|
|
44
|
+
"format.durationStyle": "Duration style",
|
|
45
|
+
"format.display": "Shown as",
|
|
46
|
+
"code.fixed": "Currency",
|
|
47
|
+
of: "A range of",
|
|
48
|
+
period: "Per",
|
|
49
|
+
ahead: "A date to look forward to",
|
|
50
|
+
"format.dateStyle": "Date style",
|
|
51
|
+
"format.withTime": "Show the time",
|
|
52
|
+
options: "Options",
|
|
53
|
+
vocabulary: "Values allowed",
|
|
54
|
+
"validation.maxItems": "Most values",
|
|
55
|
+
normalize: "Tidy each value",
|
|
56
|
+
"relation.kind": "Links to",
|
|
57
|
+
cardinality: "How many",
|
|
58
|
+
multiple: "Holds several values",
|
|
59
|
+
parts: "Parts of the place",
|
|
60
|
+
};
|
|
61
|
+
const SETTING_LABEL_BY_TYPE = {
|
|
62
|
+
multiselect: { "validation.maxItems": "Most choices" },
|
|
63
|
+
name: { "validation.maxLength": "Most characters in each part" },
|
|
64
|
+
location: { "validation.maxLength": "Most characters in each part" },
|
|
65
|
+
};
|
|
66
|
+
const SETTING_WORDS = {
|
|
67
|
+
storage: { number: "Number", decimal: "Exact decimal" },
|
|
68
|
+
"format.style": {
|
|
69
|
+
plain: "Number",
|
|
70
|
+
duration: "Duration",
|
|
71
|
+
checkbox: "Checkbox",
|
|
72
|
+
icon: "Icon",
|
|
73
|
+
marker: "Marker",
|
|
74
|
+
text: "Words",
|
|
75
|
+
},
|
|
76
|
+
"format.signedTone": { "positive-good": "Up is good", neutral: "Neutral" },
|
|
77
|
+
"format.unit": { ms: "Milliseconds", s: "Seconds" },
|
|
78
|
+
"format.durationStyle": { adaptive: "Adaptive", clock: "Clock", units: "Units" },
|
|
79
|
+
"format.display": { text: "Number", bar: "Bar", ring: "Ring" },
|
|
80
|
+
of: { number: "Numbers", currency: "Amounts", percent: "Percents" },
|
|
81
|
+
period: { hour: "Hour", day: "Day", week: "Week", month: "Month", year: "Year" },
|
|
82
|
+
"format.dateStyle": { short: "Short", long: "Long", numeric: "Numbers only", relative: "Relative" },
|
|
83
|
+
vocabulary: { closed: "Only the listed options", "custom-values": "Any value typed in" },
|
|
84
|
+
normalize: { trim: "Trim spaces", lowercase: "Lowercase", hyphenate: "Spaces to hyphens" },
|
|
85
|
+
cardinality: { one: "One record", many: "Several records" },
|
|
86
|
+
parts: {
|
|
87
|
+
line1: "Address line 1",
|
|
88
|
+
line2: "Address line 2",
|
|
89
|
+
postalCode: "Postal code",
|
|
90
|
+
city: "City",
|
|
91
|
+
region: "Region",
|
|
92
|
+
regionCode: "Region code",
|
|
93
|
+
countryCode: "Country",
|
|
94
|
+
},
|
|
95
|
+
};
|
|
27
96
|
const ROLLUP_VERB = {
|
|
28
97
|
sum: "The sum of",
|
|
29
98
|
avg: "The average",
|
|
@@ -82,6 +151,7 @@ const DUE_BUCKET_WORD = {
|
|
|
82
151
|
next_7_days: "Next 7 days",
|
|
83
152
|
next_30_days: "Next 30 days",
|
|
84
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"}`;
|
|
85
155
|
export const resolveFieldMessage = (message) => {
|
|
86
156
|
switch (message.key) {
|
|
87
157
|
case "lock.system":
|
|
@@ -114,6 +184,12 @@ export const resolveFieldMessage = (message) => {
|
|
|
114
184
|
return message.values.provider;
|
|
115
185
|
case "type.label":
|
|
116
186
|
return TYPE_LABELS[message.values.type];
|
|
187
|
+
case "setting.label": {
|
|
188
|
+
const { type, path } = message.values;
|
|
189
|
+
return SETTING_LABEL_BY_TYPE[type]?.[path] ?? SETTING_LABELS[path] ?? path;
|
|
190
|
+
}
|
|
191
|
+
case "setting.word":
|
|
192
|
+
return SETTING_WORDS[message.values.path]?.[message.values.word] ?? message.values.word;
|
|
117
193
|
case "field.cannot-empty":
|
|
118
194
|
return "This field can't be emptied";
|
|
119
195
|
case "field.cannot-edit":
|
|
@@ -170,6 +246,34 @@ export const resolveFieldMessage = (message) => {
|
|
|
170
246
|
return "HH:MM";
|
|
171
247
|
case "time.label":
|
|
172
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`;
|
|
173
277
|
case "chips.add-placeholder":
|
|
174
278
|
return "Add a value…";
|
|
175
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,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
|
|
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
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
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
|
-
|
|
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
|
|
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
|
|
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) {
|
package/fields/dist/registry.js
CHANGED
|
@@ -8,7 +8,7 @@ import { NORMALIZE_STEPS } from "./normalize.js";
|
|
|
8
8
|
import { isDecimalText } from "./parse-number.js";
|
|
9
9
|
import { LOCATION_PARTS } from "./location.js";
|
|
10
10
|
import { isMultipleType } from "./value-list.js";
|
|
11
|
-
import { buildFieldSchema } from "./zod.js";
|
|
11
|
+
import { buildFieldSchema, readPattern } from "./zod.js";
|
|
12
12
|
export const FIELD_TYPES = [
|
|
13
13
|
"text",
|
|
14
14
|
"number",
|
|
@@ -463,12 +463,9 @@ export function checkFieldSpec(key, spec, all = {}, context = {}) {
|
|
|
463
463
|
if (f.emptiable && v?.minLength)
|
|
464
464
|
fail("an emptiable field cannot state a minLength above 0");
|
|
465
465
|
if (v?.pattern !== undefined) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
catch {
|
|
470
|
-
fail("pattern is not a valid regular expression");
|
|
471
|
-
}
|
|
466
|
+
const read = readPattern(v.pattern);
|
|
467
|
+
if (!read.ok)
|
|
468
|
+
fail(`pattern ${read.why}`);
|
|
472
469
|
}
|
|
473
470
|
}
|
|
474
471
|
if (f.type === "location" && f.parts !== undefined) {
|
|
@@ -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"];
|