@mdbase-dev/ui 0.2.1 → 0.2.2

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 (67) hide show
  1. package/README.md +119 -0
  2. package/css/controls.css +37 -0
  3. package/css/date-picker.css +176 -0
  4. package/css/filter-builder.css +336 -0
  5. package/css/properties.css +398 -0
  6. package/dist/AnchoredPopover.d.ts +20 -0
  7. package/dist/AnchoredPopover.js +100 -0
  8. package/dist/Combo.d.ts +41 -0
  9. package/dist/Combo.js +82 -0
  10. package/dist/DatePicker.d.ts +69 -0
  11. package/dist/DatePicker.js +317 -0
  12. package/dist/Menu.d.ts +3 -1
  13. package/dist/Menu.js +3 -2
  14. package/dist/QuickCreate.js +1 -16
  15. package/dist/date-picker-model.d.ts +31 -0
  16. package/dist/date-picker-model.js +97 -0
  17. package/dist/filter-builder/AddFilter.d.ts +13 -0
  18. package/dist/filter-builder/AddFilter.js +295 -0
  19. package/dist/filter-builder/FilterBuilder.d.ts +36 -0
  20. package/dist/filter-builder/FilterBuilder.js +225 -0
  21. package/dist/filter-builder/FilterPill.d.ts +17 -0
  22. package/dist/filter-builder/FilterPill.js +494 -0
  23. package/dist/filter-builder/context.d.ts +40 -0
  24. package/dist/filter-builder/context.js +67 -0
  25. package/dist/filter-builder/editors.d.ts +31 -0
  26. package/dist/filter-builder/editors.js +294 -0
  27. package/dist/filter-builder/filter-ast.d.ts +13 -0
  28. package/dist/filter-builder/filter-ast.js +382 -0
  29. package/dist/filter-builder/labels.d.ts +99 -0
  30. package/dist/filter-builder/labels.js +555 -0
  31. package/dist/filter-builder/menu.d.ts +21 -0
  32. package/dist/filter-builder/menu.js +60 -0
  33. package/dist/filter-builder/operators.d.ts +30 -0
  34. package/dist/filter-builder/operators.js +192 -0
  35. package/dist/filter-builder/tree.d.ts +12 -0
  36. package/dist/filter-builder/tree.js +61 -0
  37. package/dist/filter-builder/types.d.ts +69 -0
  38. package/dist/filter-builder/types.js +48 -0
  39. package/dist/filter-builder.d.ts +13 -0
  40. package/dist/filter-builder.js +10 -0
  41. package/dist/glyphs.d.ts +32 -0
  42. package/dist/glyphs.js +143 -0
  43. package/dist/locales/de/messages.json +1 -1
  44. package/dist/locales/en/messages.json +1 -1
  45. package/dist/locales/es/messages.json +1 -1
  46. package/dist/locales/fr/messages.json +1 -1
  47. package/dist/locales/it/messages.json +1 -1
  48. package/dist/locales/ja/messages.json +1 -1
  49. package/dist/locales/ko/messages.json +1 -1
  50. package/dist/locales/pt/messages.json +1 -1
  51. package/dist/locales/ru/messages.json +1 -1
  52. package/dist/locales/zh/messages.json +1 -1
  53. package/dist/popover.d.ts +5 -0
  54. package/dist/popover.js +15 -0
  55. package/dist/properties/PropertyList.d.ts +31 -0
  56. package/dist/properties/PropertyList.js +233 -0
  57. package/dist/properties/PropertyValue.d.ts +42 -0
  58. package/dist/properties/PropertyValue.js +304 -0
  59. package/dist/properties/fields.d.ts +20 -0
  60. package/dist/properties/fields.js +81 -0
  61. package/dist/properties/labels.d.ts +29 -0
  62. package/dist/properties/labels.js +127 -0
  63. package/dist/properties/model.d.ts +52 -0
  64. package/dist/properties/model.js +195 -0
  65. package/dist/properties.d.ts +13 -0
  66. package/dist/properties.js +9 -0
  67. package/package.json +25 -2
@@ -0,0 +1,42 @@
1
+ import { type JSX } from "react";
2
+ import { type PropertyLabels } from "./labels.js";
3
+ import { type PropertyInfo, type PropertyKind } from "./model.js";
4
+ /** What the editors need to know about the other records, for properties that link to them. */
5
+ export interface PropertyRecords {
6
+ /** A record's title and kind, when it is known. */
7
+ describe(path: string): {
8
+ readonly title: string;
9
+ readonly detail?: string | undefined;
10
+ } | undefined;
11
+ /** Records whose title matches what was typed, best first. */
12
+ search(query: string): readonly {
13
+ readonly path: string;
14
+ readonly title: string;
15
+ readonly detail?: string | undefined;
16
+ }[];
17
+ /** Show the record. Without it a link is only named. */
18
+ readonly open?: ((path: string) => void) | undefined;
19
+ }
20
+ export interface PropertyValueProps {
21
+ /** The property's name, which also names its control. */
22
+ readonly name: string;
23
+ readonly value: unknown;
24
+ readonly info: PropertyInfo | undefined;
25
+ /** How to show the value: `propertyKind(value, info)`. */
26
+ readonly kind: PropertyKind;
27
+ /** Values worth offering for a property that may hold any text. */
28
+ readonly suggestions?: readonly string[] | undefined;
29
+ readonly records?: PropertyRecords | undefined;
30
+ /** Put the keyboard in the control when it appears, opening it where there is something to open. */
31
+ readonly autoFocus?: boolean | undefined;
32
+ /** Read typed text for the value it most plainly means: a number, true or false. */
33
+ readonly loose?: boolean | undefined;
34
+ /** Absent when the value cannot be changed: it is then only shown. */
35
+ readonly onChange: ((value: unknown) => void) | undefined;
36
+ /** The control was left. */
37
+ readonly onDone?: (() => void) | undefined;
38
+ /** Text to show in place of the shared catalogue's. */
39
+ readonly labels?: Partial<PropertyLabels> | undefined;
40
+ }
41
+ /** One property's value, edited in place with the control it calls for. */
42
+ export declare function PropertyValue(props: PropertyValueProps): JSX.Element;
@@ -0,0 +1,304 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useMemo, useRef, useState } from "react";
3
+ import { Combo } from "../Combo.js";
4
+ import { DateField } from "../DatePicker.js";
5
+ import { Glyph } from "../glyphs.js";
6
+ import { useLocaleRevision } from "../i18n.js";
7
+ import { LinkPicker } from "../LinkPicker.js";
8
+ import { Select } from "../Select.js";
9
+ import { Switch } from "../Switch.js";
10
+ import { CommitArea, CommitInput } from "./fields.js";
11
+ import { propertyLabels } from "./labels.js";
12
+ import { isLink, linkLabel, linkToPath, parseValue, pathToLink, valueLine } from "./model.js";
13
+ const noRecords = {
14
+ describe: () => undefined,
15
+ search: () => []
16
+ };
17
+ /** The choice that clears the value: no option a type lists is this. */
18
+ const CLEAR = "\u0000";
19
+ /** One property's value, edited in place with the control it calls for. */
20
+ export function PropertyValue(props) {
21
+ useLocaleRevision();
22
+ const labels = {
23
+ ...propertyLabels(),
24
+ ...props.labels
25
+ };
26
+ const {
27
+ value,
28
+ info,
29
+ onChange,
30
+ name,
31
+ kind
32
+ } = props;
33
+ const records = props.records ?? noRecords;
34
+ const readOnly = text => _jsx("span", {
35
+ className: text ? "mdbase-property-static" : "mdbase-property-static is-empty",
36
+ children: text ?? labels.empty
37
+ });
38
+ const trigger = useRef(null);
39
+ const opened = useRef(false);
40
+ useEffect(() => {
41
+ // A choice asked for by name opens, so the next key chooses.
42
+ if (props.autoFocus && !opened.current && trigger.current) {
43
+ opened.current = true;
44
+ trigger.current.focus({
45
+ preventScroll: true
46
+ });
47
+ trigger.current.click();
48
+ }
49
+ }, [props.autoFocus]);
50
+ const typedValue = typed => typed.trim() === "" ? null : props.loose ? parseValue(typed) : typed;
51
+ const line = held => valueLine(held, labels);
52
+ if (kind === "links") return _jsx(LinksValue, {
53
+ name: name,
54
+ value: value,
55
+ labels: labels,
56
+ records: records,
57
+ onChange: onChange
58
+ });
59
+ if (!onChange) return readOnly(line(value) ?? (value === undefined || value === null ? undefined : typeof value === "string" ? value : JSON.stringify(value)));
60
+ switch (kind) {
61
+ case "choice":
62
+ {
63
+ const options = info?.options ?? [];
64
+ const unset = value === undefined || value === null;
65
+ const all = unset || value === "" || options.some(option => option === value) ? options : [value, ...options];
66
+ return _jsx(Select, {
67
+ ref: trigger,
68
+ className: "is-quiet mdbase-property-select",
69
+ "aria-label": name,
70
+ value: unset ? "" : String(value),
71
+ placeholder: labels.empty,
72
+ options: [...all.map(option => ({
73
+ value: String(option),
74
+ label: String(option)
75
+ })), ...(unset ? [] : [{
76
+ value: CLEAR,
77
+ label: labels.clearValue
78
+ }])],
79
+ onChange: picked => onChange(picked === CLEAR ? null : all.find(option => String(option) === picked) ?? null),
80
+ onBlur: props.onDone
81
+ });
82
+ }
83
+ case "boolean":
84
+ return _jsx(Switch, {
85
+ checked: value === true,
86
+ onChange: checked => onChange(checked),
87
+ "aria-label": name
88
+ });
89
+ case "tags":
90
+ return _jsx(TagsValue, {
91
+ name: name,
92
+ items: Array.isArray(value) ? value.map(String) : [],
93
+ labels: labels,
94
+ autoFocus: Boolean(props.autoFocus),
95
+ onChange: items => onChange(items.length ? items : value === undefined ? null : []),
96
+ onDone: props.onDone
97
+ });
98
+ case "number":
99
+ return _jsx(CommitInput, {
100
+ className: "mdbase-property-input",
101
+ value: value === undefined || value === null ? "" : String(value),
102
+ placeholder: labels.empty,
103
+ label: name,
104
+ inputMode: "decimal",
105
+ autoFocus: Boolean(props.autoFocus),
106
+ onCommit: typed => {
107
+ const number = Number(typed);
108
+ onChange(typed.trim() === "" ? null : Number.isFinite(number) ? number : typed);
109
+ },
110
+ onDone: props.onDone
111
+ });
112
+ case "date":
113
+ return _jsx(DateField, {
114
+ className: "mdbase-property-date",
115
+ value: typeof value === "string" ? value : "",
116
+ placeholder: labels.empty,
117
+ label: name,
118
+ labels: labels.date,
119
+ defaultOpen: Boolean(props.autoFocus),
120
+ onChange: onChange,
121
+ onClose: props.onDone
122
+ });
123
+ case "long":
124
+ return _jsx(CommitArea, {
125
+ className: "mdbase-property-input",
126
+ value: typeof value === "string" ? value : "",
127
+ placeholder: labels.empty,
128
+ label: name,
129
+ onCommit: typed => onChange(typed.trim() === "" ? null : typed)
130
+ });
131
+ case "text":
132
+ return props.suggestions?.length ? _jsx(Combo, {
133
+ className: "mdbase-property-combo",
134
+ label: name,
135
+ placeholder: labels.empty,
136
+ value: typeof value === "string" ? value : "",
137
+ options: props.suggestions.map(option => ({
138
+ value: option
139
+ })),
140
+ newLabel: labels.useValue,
141
+ emptyMessage: labels.noMatches,
142
+ autoFocus: Boolean(props.autoFocus),
143
+ commitOnBlur: true,
144
+ onCommit: typed => {
145
+ onChange(typedValue(typed));
146
+ props.onDone?.();
147
+ },
148
+ onCancel: props.onDone
149
+ }) : _jsx(CommitInput, {
150
+ className: "mdbase-property-input",
151
+ value: typeof value === "string" ? value : "",
152
+ placeholder: labels.empty,
153
+ label: name,
154
+ autoFocus: Boolean(props.autoFocus),
155
+ onCommit: typed => onChange(typedValue(typed)),
156
+ onDone: props.onDone
157
+ });
158
+ default:
159
+ return readOnly(line(value) ?? JSON.stringify(value));
160
+ }
161
+ }
162
+ /** A list of short values as chips: Enter or a comma adds one, Backspace takes the last away. */
163
+ function TagsValue(props) {
164
+ const [draft, setDraft] = useState("");
165
+ const field = useRef(null);
166
+ useEffect(() => {
167
+ if (props.autoFocus) field.current?.focus({
168
+ preventScroll: true
169
+ });
170
+ }, [props.autoFocus]);
171
+ const add = () => {
172
+ const next = draft.split(",").map(item => item.trim()).filter(item => item && !props.items.includes(item));
173
+ setDraft("");
174
+ if (next.length) props.onChange([...props.items, ...next]);
175
+ };
176
+ return _jsxs("div", {
177
+ className: "mdbase-tokens",
178
+ "data-editable": "",
179
+ children: [props.items.map(item => _jsxs("span", {
180
+ className: "mdbase-token",
181
+ children: [item, _jsx("button", {
182
+ type: "button",
183
+ "aria-label": props.labels.removeValue(item),
184
+ onClick: () => props.onChange(props.items.filter(other => other !== item)),
185
+ children: _jsx(Glyph, {
186
+ name: "close",
187
+ size: 10
188
+ })
189
+ })]
190
+ }, item)), _jsx("input", {
191
+ ref: field,
192
+ className: "mdbase-tokens-input",
193
+ value: draft,
194
+ placeholder: props.items.length ? "" : props.labels.empty,
195
+ "aria-label": props.name,
196
+ "data-autofocus": props.autoFocus ? "" : undefined,
197
+ onChange: event => setDraft(event.target.value),
198
+ onBlur: () => {
199
+ add();
200
+ props.onDone?.();
201
+ },
202
+ onKeyDown: event => {
203
+ if (event.key === "Enter" || event.key === ",") {
204
+ event.preventDefault();
205
+ event.stopPropagation();
206
+ add();
207
+ } else if (event.key === "Backspace" && !draft && props.items.length) {
208
+ props.onChange(props.items.slice(0, -1));
209
+ } else if (event.key === "Escape") {
210
+ // Escape first gives up what is half typed; pressed again it is the host's to close on.
211
+ if (draft) {
212
+ event.stopPropagation();
213
+ setDraft("");
214
+ } else event.currentTarget.blur();
215
+ }
216
+ }
217
+ })]
218
+ });
219
+ }
220
+ /** Links to other records as chips that open the record; more are found by typing. */
221
+ function LinksValue(props) {
222
+ const {
223
+ labels,
224
+ records
225
+ } = props;
226
+ const [picking, setPicking] = useState(false);
227
+ const [query, setQuery] = useState("");
228
+ const single = !Array.isArray(props.value);
229
+ const links = (Array.isArray(props.value) ? props.value : [props.value]).filter(isLink);
230
+ const paths = links.map(link => linkToPath(link));
231
+ const options = useMemo(() => picking ? records.search(query).filter(found => !paths.includes(found.path)).slice(0, 30) : [],
232
+ // eslint-disable-next-line react-hooks/exhaustive-deps -- the paths are compared by what they say.
233
+ [picking, query, records, paths.join("\n")]);
234
+ const write = next => props.onChange?.(next.length ? single && next.length === 1 ? next[0] : next : null);
235
+ const open = records.open;
236
+ return _jsxs("div", {
237
+ className: "mdbase-tokens",
238
+ "data-links": "",
239
+ children: [links.map((link, index) => {
240
+ const path = paths[index] ?? null;
241
+ const known = path === null ? undefined : records.describe(path);
242
+ const title = known?.title ?? linkLabel(link);
243
+ return _jsxs("span", {
244
+ className: "mdbase-token",
245
+ "data-link": "",
246
+ "data-missing": known ? undefined : "",
247
+ children: [open && path !== null ? _jsx("button", {
248
+ type: "button",
249
+ className: "mdbase-token-open",
250
+ title: path,
251
+ onClick: () => open(path),
252
+ children: title
253
+ }) : _jsx("span", {
254
+ className: "mdbase-token-open",
255
+ title: path ?? undefined,
256
+ children: title
257
+ }), props.onChange ? _jsx("button", {
258
+ type: "button",
259
+ "aria-label": labels.removeValue(title),
260
+ onClick: () => write(links.filter(other => other !== link)),
261
+ children: _jsx(Glyph, {
262
+ name: "close",
263
+ size: 10
264
+ })
265
+ }) : null]
266
+ }, link);
267
+ }), props.onChange ? picking ? _jsx(LinkPicker, {
268
+ className: "mdbase-property-link-picker",
269
+ label: labels.linkRecord(props.name),
270
+ placeholder: labels.findRecord,
271
+ query: query,
272
+ onQueryChange: setQuery,
273
+ options: options.map(found => ({
274
+ id: found.path,
275
+ title: found.title,
276
+ ...(found.detail ? {
277
+ detail: found.detail
278
+ } : {})
279
+ })),
280
+ emptyMessage: labels.noMatches,
281
+ autoFocus: true,
282
+ onPick: option => {
283
+ write([...links, pathToLink(option.id)]);
284
+ setQuery("");
285
+ setPicking(false);
286
+ },
287
+ onClose: () => {
288
+ setQuery("");
289
+ setPicking(false);
290
+ }
291
+ }) : _jsx("button", {
292
+ type: "button",
293
+ className: "mdbase-token-add",
294
+ "data-autofocus": "",
295
+ "aria-label": labels.linkRecord(props.name),
296
+ title: labels.linkRecord(props.name),
297
+ onClick: () => setPicking(true),
298
+ children: _jsx(Glyph, {
299
+ name: "plus",
300
+ size: 12
301
+ })
302
+ }) : null]
303
+ });
304
+ }
@@ -0,0 +1,20 @@
1
+ import { type JSX } from "react";
2
+ /** A text field that keeps its own text while typed in and hands it over on Enter or when left. */
3
+ export declare function CommitInput(props: {
4
+ readonly value: string;
5
+ readonly placeholder?: string | undefined;
6
+ readonly label: string;
7
+ readonly autoFocus?: boolean | undefined;
8
+ readonly className: string;
9
+ readonly inputMode?: "decimal" | "text" | undefined;
10
+ readonly onCommit: (value: string) => void;
11
+ readonly onDone?: (() => void) | undefined;
12
+ }): JSX.Element;
13
+ /** A text area that grows with its text and commits as `CommitInput` does; Enter is a new line. */
14
+ export declare function CommitArea(props: {
15
+ readonly value: string;
16
+ readonly placeholder?: string | undefined;
17
+ readonly label: string;
18
+ readonly className: string;
19
+ readonly onCommit: (value: string) => void;
20
+ }): JSX.Element;
@@ -0,0 +1,81 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ /** A text field that keeps its own text while typed in and hands it over on Enter or when left. */
4
+ export function CommitInput(props) {
5
+ const [text, setText] = useState(props.value);
6
+ const ref = useRef(null);
7
+ const cancelled = useRef(false);
8
+ useEffect(() => setText(props.value), [props.value]);
9
+ useEffect(() => {
10
+ if (props.autoFocus) {
11
+ // The host decides what scrolls: a canvas must not shift under its camera.
12
+ ref.current?.focus({
13
+ preventScroll: true
14
+ });
15
+ ref.current?.select();
16
+ }
17
+ }, [props.autoFocus]);
18
+ return _jsx("input", {
19
+ ref: ref,
20
+ className: props.className,
21
+ "data-autofocus": props.autoFocus ? "" : undefined,
22
+ type: "text",
23
+ inputMode: props.inputMode,
24
+ value: text,
25
+ placeholder: props.placeholder,
26
+ "aria-label": props.label,
27
+ onChange: event => setText(event.target.value),
28
+ onBlur: () => {
29
+ if (!cancelled.current && text !== props.value) props.onCommit(text);
30
+ cancelled.current = false;
31
+ props.onDone?.();
32
+ },
33
+ onKeyDown: event => {
34
+ if (event.key !== "Enter" && event.key !== "Escape") return;
35
+ // The key ends the edit; it is not also the host's Enter or Escape.
36
+ event.stopPropagation();
37
+ if (event.key === "Escape") {
38
+ cancelled.current = true;
39
+ setText(props.value);
40
+ }
41
+ event.currentTarget.blur();
42
+ }
43
+ });
44
+ }
45
+ /** A text area that grows with its text and commits as `CommitInput` does; Enter is a new line. */
46
+ export function CommitArea(props) {
47
+ const [text, setText] = useState(props.value);
48
+ const ref = useRef(null);
49
+ const cancelled = useRef(false);
50
+ useEffect(() => setText(props.value), [props.value]);
51
+ useEffect(() => {
52
+ const element = ref.current;
53
+ if (element) {
54
+ element.style.height = "auto";
55
+ element.style.height = `${String(element.scrollHeight + 2)}px`;
56
+ }
57
+ }, [text]);
58
+ return _jsx("textarea", {
59
+ ref: ref,
60
+ className: props.className,
61
+ rows: 1,
62
+ value: text,
63
+ placeholder: props.placeholder,
64
+ "aria-label": props.label,
65
+ onChange: event => setText(event.target.value),
66
+ onBlur: () => {
67
+ if (!cancelled.current && text !== props.value) props.onCommit(text);
68
+ cancelled.current = false;
69
+ },
70
+ onKeyDown: event => {
71
+ const done = event.key === "Enter" && (event.metaKey || event.ctrlKey);
72
+ if (event.key !== "Escape" && !done) return;
73
+ event.stopPropagation();
74
+ if (event.key === "Escape") {
75
+ cancelled.current = true;
76
+ setText(props.value);
77
+ }
78
+ event.currentTarget.blur();
79
+ }
80
+ });
81
+ }
@@ -0,0 +1,29 @@
1
+ import { type DateLabels } from "../DatePicker.js";
2
+ /** Every piece of text the property list shows. A host passes the ones it words differently. */
3
+ export interface PropertyLabels {
4
+ /** A value that holds nothing. */
5
+ empty: string;
6
+ noProperties: string;
7
+ addProperty: string;
8
+ findProperty: string;
9
+ /** Before a typed name that no property has yet. */
10
+ newProperty: string;
11
+ /** Before typed text that none of the offered values is. */
12
+ useValue: string;
13
+ showEmpty: (count: number) => string;
14
+ hideEmpty: string;
15
+ propertyNameInvalid: string;
16
+ removeProperty: (name: string) => string;
17
+ removeValue: (value: string) => string;
18
+ clearValue: string;
19
+ linkRecord: (property: string) => string;
20
+ findRecord: string;
21
+ noMatches: string;
22
+ /** A true or false value where it is only shown. */
23
+ yes: string;
24
+ no: string;
25
+ /** The date picker's text. */
26
+ date: DateLabels;
27
+ }
28
+ /** The property list's text in the current language. */
29
+ export declare function propertyLabels(): PropertyLabels;
@@ -0,0 +1,127 @@
1
+ import { i18n as _i18n } from "@lingui/core";
2
+ import { dateLabels } from "../DatePicker.js";
3
+ /** The property list's text in the current language. */
4
+ export function propertyLabels() {
5
+ return {
6
+ empty: _i18n._(
7
+ /** i18n */
8
+ {
9
+ id: "VPMPqN",
10
+ message: "Empty",
11
+ context: "A property with no value"
12
+ }),
13
+ noProperties: _i18n._(
14
+ /** i18n */
15
+ {
16
+ id: "iw7_rX",
17
+ message: "No properties."
18
+ }),
19
+ addProperty: _i18n._(
20
+ /** i18n */
21
+ {
22
+ id: "F-NRCj",
23
+ message: "Add property"
24
+ }),
25
+ findProperty: _i18n._(
26
+ /** i18n */
27
+ {
28
+ id: "aRQRsv",
29
+ message: "Find a property, or name a new one\u2026"
30
+ }),
31
+ newProperty: _i18n._(
32
+ /** i18n */
33
+ {
34
+ id: "Nx5mjG",
35
+ message: "New property"
36
+ }),
37
+ useValue: _i18n._(
38
+ /** i18n */
39
+ {
40
+ id: "LCGo9Q",
41
+ message: "Use",
42
+ context: "Before typed text, to take it as the value"
43
+ }),
44
+ showEmpty: count => _i18n._(
45
+ /** i18n */
46
+ {
47
+ id: "GmaX59",
48
+ message: "{count, plural, one {# empty} other {# empty}}",
49
+ values: {
50
+ count: count
51
+ }
52
+ }),
53
+ hideEmpty: _i18n._(
54
+ /** i18n */
55
+ {
56
+ id: "5JawYP",
57
+ message: "Hide empty"
58
+ }),
59
+ propertyNameInvalid: _i18n._(
60
+ /** i18n */
61
+ {
62
+ id: "emVWqz",
63
+ message: "Use letters, digits, - and _, starting with a letter."
64
+ }),
65
+ removeProperty: name => _i18n._(
66
+ /** i18n */
67
+ {
68
+ id: "HLazKQ",
69
+ message: "Remove {name}",
70
+ values: {
71
+ name: name
72
+ }
73
+ }),
74
+ removeValue: value => _i18n._(
75
+ /** i18n */
76
+ {
77
+ id: "d38bWj",
78
+ message: "Remove {value}",
79
+ values: {
80
+ value: value
81
+ }
82
+ }),
83
+ clearValue: _i18n._(
84
+ /** i18n */
85
+ {
86
+ id: "3eQML0",
87
+ message: "Clear",
88
+ context: "Remove a property's value"
89
+ }),
90
+ linkRecord: property => _i18n._(
91
+ /** i18n */
92
+ {
93
+ id: "6vBAH4",
94
+ message: "Link a record in {property}",
95
+ values: {
96
+ property: property
97
+ }
98
+ }),
99
+ findRecord: _i18n._(
100
+ /** i18n */
101
+ {
102
+ id: "VWWfAK",
103
+ message: "Find a record\u2026"
104
+ }),
105
+ noMatches: _i18n._(
106
+ /** i18n */
107
+ {
108
+ id: "Htmc3F",
109
+ message: "Nothing matches."
110
+ }),
111
+ yes: _i18n._(
112
+ /** i18n */
113
+ {
114
+ id: "wu_dAl",
115
+ message: "yes",
116
+ context: "A property that is true"
117
+ }),
118
+ no: _i18n._(
119
+ /** i18n */
120
+ {
121
+ id: "R8ZgzG",
122
+ message: "no",
123
+ context: "A property that is false"
124
+ }),
125
+ date: dateLabels()
126
+ };
127
+ }
@@ -0,0 +1,52 @@
1
+ import type { FilterFieldSpec } from "../filter-builder/types.js";
2
+ /** A value a property holds on its own, outside a list or a group. */
3
+ export type PropertyScalar = string | number | boolean | null;
4
+ /** What is known about a property: what a type declares for it, or what records hold for it. */
5
+ export interface PropertyInfo {
6
+ readonly name: string;
7
+ readonly kind: "text" | "number" | "boolean" | "list" | "other";
8
+ /** The values the property may take, when they are listed. */
9
+ readonly options?: readonly PropertyScalar[] | undefined;
10
+ /** `date` or `date-time`, when that is known. */
11
+ readonly format?: string | undefined;
12
+ }
13
+ /** How a property is shown and edited. */
14
+ export type PropertyKind = "choice" | "boolean" | "date" | "number" | "tags" | "links" | "text" | "long" | "other";
15
+ export declare const isLink: (value: unknown) => value is string;
16
+ export declare const isScalar: (value: unknown) => value is PropertyScalar;
17
+ export declare const isGroup: (value: unknown) => value is Readonly<Record<string, unknown>>;
18
+ /** Whether text can name a property: letters, digits, `-`, `_` and `:`, not starting with a digit. */
19
+ export declare const isPropertyName: (text: string) => boolean;
20
+ /** Whether a property holds nothing: it is absent, null, empty text, or a list or group of nothing. */
21
+ export declare function isEmptyValue(value: unknown): boolean;
22
+ /** Text someone typed as the value it most plainly means. */
23
+ export declare function parseValue(text: string): PropertyScalar;
24
+ /** What a value is, going by what it holds first and by what is known of the property when it holds nothing. */
25
+ export declare function propertyKind(value: unknown, info: PropertyInfo | undefined): PropertyKind;
26
+ /** What is known about a property: what the record's type declares, or failing that what other records hold for it. */
27
+ export declare function describeProperty(property: string, declared: readonly PropertyInfo[], inUse: readonly PropertyInfo[]): {
28
+ info: PropertyInfo | undefined;
29
+ suggestions: readonly string[] | undefined;
30
+ own: boolean;
31
+ };
32
+ /** `[[sources/crime|Crime]]`, `[[sources/crime#p3]]` or a bare path, as a collection path. */
33
+ export declare function linkToPath(link: string): string | null;
34
+ /** A record's path as the wikilink that is rewritten when the record is renamed. */
35
+ export declare function pathToLink(path: string): string;
36
+ /** `[[sources/crime|Crime and Punishment]]` as "Crime and Punishment". Other text is left alone. */
37
+ export declare function linkLabel(value: string): string;
38
+ /** A value as one short line of text, or undefined when it does not fit on one. */
39
+ export declare function valueLine(value: unknown, words: {
40
+ readonly yes: string;
41
+ readonly no: string;
42
+ }): string | undefined;
43
+ /** What a property is, going by the values records hold for it. Undefined when there are none. */
44
+ export declare function inferProperty(property: string, values: readonly unknown[]): PropertyInfo | undefined;
45
+ /**
46
+ * The properties to offer for a set of records: the declared ones first, in their order, then
47
+ * whatever else the records hold, each described by the values held for it. `skip` leaves a
48
+ * name out of what is inferred, as for the properties that are an app's own machinery.
49
+ */
50
+ export declare function propertiesInUse(records: Iterable<Readonly<Record<string, unknown>>>, declared?: readonly PropertyInfo[], skip?: (property: string) => boolean): PropertyInfo[];
51
+ /** Properties as the filter builder's fields, by name: those whose values can be compared. */
52
+ export declare function filterFieldsFromProperties(properties: readonly PropertyInfo[]): FilterFieldSpec[];