@mdbase-dev/ui 0.2.0 → 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.
- package/README.md +119 -0
- package/css/controls.css +37 -0
- package/css/date-picker.css +176 -0
- package/css/filter-builder.css +336 -0
- package/css/properties.css +398 -0
- package/dist/AnchoredPopover.d.ts +20 -0
- package/dist/AnchoredPopover.js +100 -0
- package/dist/Combo.d.ts +41 -0
- package/dist/Combo.js +82 -0
- package/dist/DatePicker.d.ts +69 -0
- package/dist/DatePicker.js +317 -0
- package/dist/Menu.d.ts +3 -1
- package/dist/Menu.js +3 -2
- package/dist/QuickCreate.js +1 -16
- package/dist/collections/CollectionGate.js +20 -13
- package/dist/collections/use-collection-ui.d.ts +14 -2
- package/dist/collections/use-collection-ui.js +13 -0
- package/dist/date-picker-model.d.ts +31 -0
- package/dist/date-picker-model.js +97 -0
- package/dist/filter-builder/AddFilter.d.ts +13 -0
- package/dist/filter-builder/AddFilter.js +295 -0
- package/dist/filter-builder/FilterBuilder.d.ts +36 -0
- package/dist/filter-builder/FilterBuilder.js +225 -0
- package/dist/filter-builder/FilterPill.d.ts +17 -0
- package/dist/filter-builder/FilterPill.js +494 -0
- package/dist/filter-builder/context.d.ts +40 -0
- package/dist/filter-builder/context.js +67 -0
- package/dist/filter-builder/editors.d.ts +31 -0
- package/dist/filter-builder/editors.js +294 -0
- package/dist/filter-builder/filter-ast.d.ts +13 -0
- package/dist/filter-builder/filter-ast.js +382 -0
- package/dist/filter-builder/labels.d.ts +99 -0
- package/dist/filter-builder/labels.js +555 -0
- package/dist/filter-builder/menu.d.ts +21 -0
- package/dist/filter-builder/menu.js +60 -0
- package/dist/filter-builder/operators.d.ts +30 -0
- package/dist/filter-builder/operators.js +192 -0
- package/dist/filter-builder/tree.d.ts +12 -0
- package/dist/filter-builder/tree.js +61 -0
- package/dist/filter-builder/types.d.ts +69 -0
- package/dist/filter-builder/types.js +48 -0
- package/dist/filter-builder.d.ts +13 -0
- package/dist/filter-builder.js +10 -0
- package/dist/glyphs.d.ts +32 -0
- package/dist/glyphs.js +143 -0
- package/dist/locales/de/messages.json +1 -1
- package/dist/locales/en/messages.json +1 -1
- package/dist/locales/es/messages.json +1 -1
- package/dist/locales/fr/messages.json +1 -1
- package/dist/locales/it/messages.json +1 -1
- package/dist/locales/ja/messages.json +1 -1
- package/dist/locales/ko/messages.json +1 -1
- package/dist/locales/pt/messages.json +1 -1
- package/dist/locales/ru/messages.json +1 -1
- package/dist/locales/zh/messages.json +1 -1
- package/dist/popover.d.ts +5 -0
- package/dist/popover.js +15 -0
- package/dist/properties/PropertyList.d.ts +31 -0
- package/dist/properties/PropertyList.js +233 -0
- package/dist/properties/PropertyValue.d.ts +42 -0
- package/dist/properties/PropertyValue.js +304 -0
- package/dist/properties/fields.d.ts +20 -0
- package/dist/properties/fields.js +81 -0
- package/dist/properties/labels.d.ts +29 -0
- package/dist/properties/labels.js +127 -0
- package/dist/properties/model.d.ts +52 -0
- package/dist/properties/model.js +195 -0
- package/dist/properties.d.ts +13 -0
- package/dist/properties.js +9 -0
- package/package.json +25 -2
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
const wholeLink = /^!?\[\[[^\]]+\]\]$/u;
|
|
2
|
+
const day = /^\d{4}-\d{2}-\d{2}$/u;
|
|
3
|
+
const instant = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/u;
|
|
4
|
+
const dateTime = /^(\d{4}-\d{2}-\d{2})T\d{2}:\d{2}\S*$/u;
|
|
5
|
+
const word = /^[\p{L}\p{N}_-]{1,24}$/u;
|
|
6
|
+
const name = /^[A-Za-z_][A-Za-z0-9_:-]*$/u;
|
|
7
|
+
/** How many different values a property may have and still be offered as a choice. */
|
|
8
|
+
const fewValues = 12;
|
|
9
|
+
export const isLink = value => typeof value === "string" && wholeLink.test(value.trim());
|
|
10
|
+
export const isScalar = value => value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
11
|
+
export const isGroup = value => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
|
+
/** Whether text can name a property: letters, digits, `-`, `_` and `:`, not starting with a digit. */
|
|
13
|
+
export const isPropertyName = text => name.test(text);
|
|
14
|
+
/** Whether a property holds nothing: it is absent, null, empty text, or a list or group of nothing. */
|
|
15
|
+
export function isEmptyValue(value) {
|
|
16
|
+
if (value === undefined || value === null || value === "") return true;
|
|
17
|
+
if (Array.isArray(value)) return value.length === 0;
|
|
18
|
+
return isGroup(value) && Object.keys(value).length === 0;
|
|
19
|
+
}
|
|
20
|
+
/** Text someone typed as the value it most plainly means. */
|
|
21
|
+
export function parseValue(text) {
|
|
22
|
+
const typed = text.trim();
|
|
23
|
+
if (typed === "null") return null;
|
|
24
|
+
if (typed === "true") return true;
|
|
25
|
+
if (typed === "false") return false;
|
|
26
|
+
return /^-?\d+(\.\d+)?$/u.test(typed) ? Number(typed) : typed;
|
|
27
|
+
}
|
|
28
|
+
/** What a value is, going by what it holds first and by what is known of the property when it holds nothing. */
|
|
29
|
+
export function propertyKind(value, info) {
|
|
30
|
+
const unset = value === undefined || value === null || value === "";
|
|
31
|
+
if (Array.isArray(value) ? value.length > 0 && value.every(isLink) : isLink(value)) return "links";
|
|
32
|
+
if (info?.options?.length && (unset || isScalar(value))) return "choice";
|
|
33
|
+
if (typeof value === "boolean" || unset && info?.kind === "boolean") return "boolean";
|
|
34
|
+
if (Array.isArray(value)) return value.every(item => typeof item === "string" || typeof item === "number") ? "tags" : "other";
|
|
35
|
+
if (unset && info?.kind === "list") return "tags";
|
|
36
|
+
if (typeof value === "number" || unset && info?.kind === "number") return "number";
|
|
37
|
+
if (typeof value === "string") {
|
|
38
|
+
if (info?.format === "date" ? day.test(value) : !info && day.test(value)) return "date";
|
|
39
|
+
return value.includes("\n") || value.length > 90 ? "long" : "text";
|
|
40
|
+
}
|
|
41
|
+
if (unset) return info?.format === "date" ? "date" : "text";
|
|
42
|
+
return "other";
|
|
43
|
+
}
|
|
44
|
+
/** What is known about a property: what the record's type declares, or failing that what other records hold for it. */
|
|
45
|
+
export function describeProperty(property, declared, inUse) {
|
|
46
|
+
const own = declared.find(field => field.name === property);
|
|
47
|
+
if (own) return {
|
|
48
|
+
info: own,
|
|
49
|
+
suggestions: undefined,
|
|
50
|
+
own: true
|
|
51
|
+
};
|
|
52
|
+
const seen = inUse.find(field => field.name === property);
|
|
53
|
+
if (!seen) return {
|
|
54
|
+
info: undefined,
|
|
55
|
+
suggestions: undefined,
|
|
56
|
+
own: false
|
|
57
|
+
};
|
|
58
|
+
// Values other records happen to hold are worth offering, but they are not all the property may hold.
|
|
59
|
+
const {
|
|
60
|
+
options,
|
|
61
|
+
...rest
|
|
62
|
+
} = seen;
|
|
63
|
+
return {
|
|
64
|
+
info: rest,
|
|
65
|
+
suggestions: options?.filter(option => typeof option === "string"),
|
|
66
|
+
own: false
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** `[[sources/crime|Crime]]`, `[[sources/crime#p3]]` or a bare path, as a collection path. */
|
|
70
|
+
export function linkToPath(link) {
|
|
71
|
+
const text = link.trim();
|
|
72
|
+
const wiki = /^!?\[\[([^\]]*)\]\]$/u.exec(text);
|
|
73
|
+
const target = (wiki ? wiki[1] : text).split("|")[0].split("#")[0].trim().replace(/^\/+/u, "");
|
|
74
|
+
if (!target || /[[\]]/u.test(target)) return null;
|
|
75
|
+
return /\.[A-Za-z0-9]{1,8}$/u.test(target) ? target : `${target}.md`;
|
|
76
|
+
}
|
|
77
|
+
/** A record's path as the wikilink that is rewritten when the record is renamed. */
|
|
78
|
+
export function pathToLink(path) {
|
|
79
|
+
return `[[${path.replace(/\.md$/u, "")}]]`;
|
|
80
|
+
}
|
|
81
|
+
function pathStem(path) {
|
|
82
|
+
const leaf = path.slice(path.lastIndexOf("/") + 1);
|
|
83
|
+
const dot = leaf.lastIndexOf(".");
|
|
84
|
+
return dot > 0 ? leaf.slice(0, dot) : leaf;
|
|
85
|
+
}
|
|
86
|
+
/** `[[sources/crime|Crime and Punishment]]` as "Crime and Punishment". Other text is left alone. */
|
|
87
|
+
export function linkLabel(value) {
|
|
88
|
+
return value.replace(/!?\[\[([^\]]+)\]\]/gu, (_all, inner) => {
|
|
89
|
+
const [target = "", alias] = inner.split("|");
|
|
90
|
+
return (alias ?? pathStem(target.split("#")[0])).trim();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/** A value as one short line of text, or undefined when it does not fit on one. */
|
|
94
|
+
export function valueLine(value, words) {
|
|
95
|
+
if (typeof value === "string") {
|
|
96
|
+
const text = linkLabel(value.trim()).replace(dateTime, "$1");
|
|
97
|
+
return text && text.length <= 80 && !text.includes("\n") ? text : undefined;
|
|
98
|
+
}
|
|
99
|
+
if (typeof value === "number") return String(value);
|
|
100
|
+
if (typeof value === "boolean") return value ? words.yes : words.no;
|
|
101
|
+
if (Array.isArray(value) && value.length && value.length <= 6 && value.every(item => typeof item === "string")) {
|
|
102
|
+
const text = value.map(item => linkLabel(item)).join(", ");
|
|
103
|
+
return text.length <= 80 ? text : undefined;
|
|
104
|
+
}
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
/** What a property is, going by the values records hold for it. Undefined when there are none. */
|
|
108
|
+
export function inferProperty(property, values) {
|
|
109
|
+
if (!values.length) return undefined;
|
|
110
|
+
if (values.every(value => typeof value === "boolean")) return {
|
|
111
|
+
name: property,
|
|
112
|
+
kind: "boolean"
|
|
113
|
+
};
|
|
114
|
+
if (values.every(value => typeof value === "number")) return {
|
|
115
|
+
name: property,
|
|
116
|
+
kind: "number"
|
|
117
|
+
};
|
|
118
|
+
if (values.every(value => Array.isArray(value))) return {
|
|
119
|
+
name: property,
|
|
120
|
+
kind: "list"
|
|
121
|
+
};
|
|
122
|
+
if (!values.every(value => typeof value === "string")) return {
|
|
123
|
+
name: property,
|
|
124
|
+
kind: "other"
|
|
125
|
+
};
|
|
126
|
+
if (values.every(value => wholeLink.test(value.trim()))) return {
|
|
127
|
+
name: property,
|
|
128
|
+
kind: "other"
|
|
129
|
+
};
|
|
130
|
+
if (values.every(value => day.test(value))) return {
|
|
131
|
+
name: property,
|
|
132
|
+
kind: "text",
|
|
133
|
+
format: "date"
|
|
134
|
+
};
|
|
135
|
+
if (values.every(value => instant.test(value))) return {
|
|
136
|
+
name: property,
|
|
137
|
+
kind: "text",
|
|
138
|
+
format: "date-time"
|
|
139
|
+
};
|
|
140
|
+
const distinct = [...new Set(values)];
|
|
141
|
+
// A handful of short values, or values that repeat, read as a set to choose from.
|
|
142
|
+
const choice = distinct.length <= fewValues && (distinct.every(value => word.test(value)) || distinct.length * 2 <= values.length);
|
|
143
|
+
return choice ? {
|
|
144
|
+
name: property,
|
|
145
|
+
kind: "text",
|
|
146
|
+
options: distinct.sort((a, b) => a.localeCompare(b))
|
|
147
|
+
} : {
|
|
148
|
+
name: property,
|
|
149
|
+
kind: "text"
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The properties to offer for a set of records: the declared ones first, in their order, then
|
|
154
|
+
* whatever else the records hold, each described by the values held for it. `skip` leaves a
|
|
155
|
+
* name out of what is inferred, as for the properties that are an app's own machinery.
|
|
156
|
+
*/
|
|
157
|
+
export function propertiesInUse(records, declared = [], skip = () => false) {
|
|
158
|
+
const out = new Map();
|
|
159
|
+
for (const field of declared) {
|
|
160
|
+
if (!out.has(field.name)) out.set(field.name, field);
|
|
161
|
+
}
|
|
162
|
+
const found = new Map();
|
|
163
|
+
for (const record of records) {
|
|
164
|
+
for (const [property, value] of Object.entries(record)) {
|
|
165
|
+
if (out.has(property) || value === null || value === undefined || value === "" || !name.test(property) || skip(property)) continue;
|
|
166
|
+
const values = found.get(property);
|
|
167
|
+
if (values) values.push(value);else found.set(property, [value]);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (const [property, values] of found) {
|
|
171
|
+
const field = inferProperty(property, values);
|
|
172
|
+
if (field) out.set(property, field);
|
|
173
|
+
}
|
|
174
|
+
return [...out.values()];
|
|
175
|
+
}
|
|
176
|
+
/** Properties as the filter builder's fields, by name: those whose values can be compared. */
|
|
177
|
+
export function filterFieldsFromProperties(properties) {
|
|
178
|
+
const out = [];
|
|
179
|
+
for (const field of properties) {
|
|
180
|
+
if (!name.test(field.name)) continue;
|
|
181
|
+
const values = field.options?.filter(option => option !== null);
|
|
182
|
+
if (values?.length) out.push({
|
|
183
|
+
key: field.name,
|
|
184
|
+
kind: "enum",
|
|
185
|
+
enumValues: values
|
|
186
|
+
});else if (field.kind === "number" || field.kind === "boolean") out.push({
|
|
187
|
+
key: field.name,
|
|
188
|
+
kind: field.kind
|
|
189
|
+
});else if (field.kind === "text") out.push({
|
|
190
|
+
key: field.name,
|
|
191
|
+
kind: field.format === "date" || field.format === "date-time" ? "date" : "string"
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return out.sort((a, b) => a.key.localeCompare(b.key));
|
|
195
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@mdbase-dev/ui/properties`: a record's properties, each edited in place with the control its
|
|
3
|
+
* value calls for, and what the list goes by: what is declared for a property and what records
|
|
4
|
+
* hold for it. Import `@mdbase-dev/ui/properties.css` and `@mdbase-dev/ui/controls.css` once.
|
|
5
|
+
*/
|
|
6
|
+
export { PropertyKindIcon, PropertyList } from "./properties/PropertyList.js";
|
|
7
|
+
export type { PropertyListProps } from "./properties/PropertyList.js";
|
|
8
|
+
export { PropertyValue } from "./properties/PropertyValue.js";
|
|
9
|
+
export type { PropertyRecords, PropertyValueProps } from "./properties/PropertyValue.js";
|
|
10
|
+
export { propertyLabels } from "./properties/labels.js";
|
|
11
|
+
export type { PropertyLabels } from "./properties/labels.js";
|
|
12
|
+
export { describeProperty, filterFieldsFromProperties, inferProperty, isEmptyValue, isPropertyName, linkLabel, linkToPath, parseValue, pathToLink, propertiesInUse, propertyKind, valueLine, } from "./properties/model.js";
|
|
13
|
+
export type { PropertyInfo, PropertyKind, PropertyScalar } from "./properties/model.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@mdbase-dev/ui/properties`: a record's properties, each edited in place with the control its
|
|
3
|
+
* value calls for, and what the list goes by: what is declared for a property and what records
|
|
4
|
+
* hold for it. Import `@mdbase-dev/ui/properties.css` and `@mdbase-dev/ui/controls.css` once.
|
|
5
|
+
*/
|
|
6
|
+
export { PropertyKindIcon, PropertyList } from "./properties/PropertyList.js";
|
|
7
|
+
export { PropertyValue } from "./properties/PropertyValue.js";
|
|
8
|
+
export { propertyLabels } from "./properties/labels.js";
|
|
9
|
+
export { describeProperty, filterFieldsFromProperties, inferProperty, isEmptyValue, isPropertyName, linkLabel, linkToPath, parseValue, pathToLink, propertiesInUse, propertyKind, valueLine } from "./properties/model.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdbase-dev/ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -84,6 +84,26 @@
|
|
|
84
84
|
"types": "./dist/ConfirmDialog.d.ts",
|
|
85
85
|
"import": "./dist/ConfirmDialog.js"
|
|
86
86
|
},
|
|
87
|
+
"./anchored-popover": {
|
|
88
|
+
"types": "./dist/AnchoredPopover.d.ts",
|
|
89
|
+
"import": "./dist/AnchoredPopover.js"
|
|
90
|
+
},
|
|
91
|
+
"./combo": {
|
|
92
|
+
"types": "./dist/Combo.d.ts",
|
|
93
|
+
"import": "./dist/Combo.js"
|
|
94
|
+
},
|
|
95
|
+
"./date-picker": {
|
|
96
|
+
"types": "./dist/DatePicker.d.ts",
|
|
97
|
+
"import": "./dist/DatePicker.js"
|
|
98
|
+
},
|
|
99
|
+
"./filter-builder": {
|
|
100
|
+
"types": "./dist/filter-builder.d.ts",
|
|
101
|
+
"import": "./dist/filter-builder.js"
|
|
102
|
+
},
|
|
103
|
+
"./properties": {
|
|
104
|
+
"types": "./dist/properties.d.ts",
|
|
105
|
+
"import": "./dist/properties.js"
|
|
106
|
+
},
|
|
87
107
|
"./link-picker": {
|
|
88
108
|
"types": "./dist/LinkPicker.d.ts",
|
|
89
109
|
"import": "./dist/LinkPicker.js"
|
|
@@ -159,12 +179,15 @@
|
|
|
159
179
|
"./brand.css": "./css/brand.css",
|
|
160
180
|
"./collections.css": "./css/collections.css",
|
|
161
181
|
"./controls.css": "./css/controls.css",
|
|
182
|
+
"./date-picker.css": "./css/date-picker.css",
|
|
162
183
|
"./comments.css": "./css/comments.css",
|
|
163
184
|
"./fonts.css": "./css/fonts.css",
|
|
164
185
|
"./live-preview.css": "./css/live-preview.css",
|
|
165
186
|
"./feedback.css": "./css/feedback.css",
|
|
187
|
+
"./filter-builder.css": "./css/filter-builder.css",
|
|
166
188
|
"./motion.css": "./css/motion.css",
|
|
167
189
|
"./palette.css": "./css/palette.css",
|
|
190
|
+
"./properties.css": "./css/properties.css",
|
|
168
191
|
"./screens.css": "./css/screens.css",
|
|
169
192
|
"./tokens.css": "./css/tokens.css"
|
|
170
193
|
},
|
|
@@ -258,6 +281,6 @@
|
|
|
258
281
|
"typecheck": "node scripts/compile-catalogues.mjs && tsc -p tsconfig.json --noEmit"
|
|
259
282
|
},
|
|
260
283
|
"mdbaseRelease": {
|
|
261
|
-
"commit": "
|
|
284
|
+
"commit": "35ff7461d0022c01d2e7865b81d720ef710e498c"
|
|
262
285
|
}
|
|
263
286
|
}
|