@weasel-js/prefs 1.9.3 → 1.9.4
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 +10 -0
- package/dist/index.d.ts +84 -12
- package/dist/index.js +321 -62
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js.map +1 -1
- package/dist/{store-BU2tRX5H.d.ts → store-CNFnA_3c.d.ts} +250 -31
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -18,3 +18,13 @@ repair stored values that no longer fit the schema without writing them back.
|
|
|
18
18
|
`usePref(store, path)` and `usePrefsValues(store)` bind it to React. They
|
|
19
19
|
live in `@weasel-js/prefs/react`, so the main entry never loads React.
|
|
20
20
|
`usePrefsValues` returns the pieces `@weasel-js/ui`'s `PrefsForm` takes.
|
|
21
|
+
|
|
22
|
+
## Ranges
|
|
23
|
+
|
|
24
|
+
A number leaf's range is one scale: the low end is the least of what its label
|
|
25
|
+
names and the high end the most. Do not give zero a second meaning such as
|
|
26
|
+
"no limit" or "automatic" — on a slider it reads as the least, and the form
|
|
27
|
+
draws it there. Put an unlimited setting at the end of the range it is nearest:
|
|
28
|
+
a 0–100% limit is off at 100, and a scale with no such end takes `endless`,
|
|
29
|
+
which adds a stop one step past the range that stores `Infinity` and reads the
|
|
30
|
+
leaf's `infinity` word.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PrefLeaf, a as PrefGroup, b as
|
|
2
|
-
export { B as BuiltinPref,
|
|
1
|
+
import { P as PrefLeaf, a as PrefGroup, b as PrefSection, c as PrefNumber, d as PrefObject, e as PrefsStore, f as PrefKind } from './store-CNFnA_3c.js';
|
|
2
|
+
export { B as BuiltinPref, g as PREF_KINDS, h as PrefAction, i as PrefActionContext, j as PrefActionControl, k as PrefAlias, l as PrefAtPath, m as PrefBase, n as PrefBoolean, o as PrefBooleanControl, p as PrefBooleanEncoding, q as PrefChange, r as PrefColor, s as PrefCustom, t as PrefEnum, u as PrefEnumBase, v as PrefEnumControl, w as PrefEnumEncoding, x as PrefField, y as PrefGroupAs, z as PrefLabel, A as PrefList, C as PrefMap, D as PrefNumberControl, E as PrefNumberUnit, F as PrefPaint, G as PrefPair, H as PrefPath, I as PrefSectionAs, J as PrefSeparator, K as PrefString, L as PrefStringControl, M as PrefUnion, N as PrefValueAt, O as PrefValueOf, Q as isBuiltinPref, R as pairRowsOf, S as prefAliasTarget, T as prefAliasedLeaf, U as prefGroupIsPage, V as prefUnit, W as prefVariantDefault, X as prefVariantOf } from './store-CNFnA_3c.js';
|
|
3
3
|
import { StorageAdapter, SyncStorageAdapter } from '@weasel-js/storage';
|
|
4
4
|
import '@weasel-js/quantity';
|
|
5
5
|
|
|
@@ -19,20 +19,40 @@ declare function prefDisplayBounds(p: PrefNumber): {
|
|
|
19
19
|
max?: number;
|
|
20
20
|
step: number;
|
|
21
21
|
};
|
|
22
|
-
/** Distinguishes a leaf from a group while walking a schema tree. */
|
|
23
|
-
declare function isPrefLeaf(node: PrefLeaf | PrefGroup): node is PrefLeaf;
|
|
22
|
+
/** Distinguishes a leaf from a group or a section while walking a schema tree. */
|
|
23
|
+
declare function isPrefLeaf(node: PrefLeaf | PrefGroup | PrefSection): node is PrefLeaf;
|
|
24
|
+
/** Whether a leaf has a value to store: an `action` is a button and holds none, an `alias` shows another leaf's,
|
|
25
|
+
* and a `label` and a `separator` are text and a rule. */
|
|
26
|
+
declare function prefHoldsValue(leaf: PrefLeaf): boolean;
|
|
27
|
+
/** Distinguishes a section, whose key adds nothing to a path, from a group, whose key is a segment. */
|
|
28
|
+
declare function isPrefSection(node: PrefLeaf | PrefGroup | PrefSection): node is PrefSection;
|
|
29
|
+
/**
|
|
30
|
+
* Every leaf under a section's `members` or an object leaf's `children`, in
|
|
31
|
+
* schema order, by its own key: the sections between contribute nothing.
|
|
32
|
+
*/
|
|
33
|
+
declare function prefSectionLeaves(members: PrefSection['members']): [key: string, leaf: PrefLeaf][];
|
|
34
|
+
/**
|
|
35
|
+
* The leaf whose value lives at `path`, as the schema's own shape builds
|
|
36
|
+
* paths: a segment per key under a {@link PrefGroup}, the leaf's own key
|
|
37
|
+
* under a {@link PrefSection}. `undefined` for a path that names a group, a
|
|
38
|
+
* field inside an `object` leaf, or nothing.
|
|
39
|
+
*/
|
|
40
|
+
declare function prefLeafAt(schema: PrefGroup | PrefSection, path: string): PrefLeaf | undefined;
|
|
24
41
|
/** Get the value at a dotted path inside a nested value tree. Returns
|
|
25
42
|
* `undefined` when a segment is missing or hits a non-object. */
|
|
26
43
|
declare function prefValueAtPath(values: unknown, path: string): unknown;
|
|
27
44
|
/**
|
|
28
|
-
* Recursively drop `hidden` leaves (unless `showHidden`),
|
|
29
|
-
*
|
|
45
|
+
* Recursively drop `hidden` leaves (unless `showHidden`), an object leaf's
|
|
46
|
+
* hidden fields among them, pruning groups
|
|
47
|
+
* that end up empty (unless `keepEmpty`). Returns null when the entire
|
|
48
|
+
* subtree is pruned.
|
|
30
49
|
*/
|
|
31
|
-
declare function visiblePrefSubtree<T extends PrefLeaf | PrefGroup>(node: T, showHidden: boolean): T | null;
|
|
50
|
+
declare function visiblePrefSubtree<T extends PrefLeaf | PrefGroup>(node: T, showHidden: boolean, keepEmpty?: boolean): T | null;
|
|
32
51
|
/** The record holding the schema version the stored values were written at.
|
|
33
52
|
* Reserved: no top-level schema key may take its name. */
|
|
34
53
|
declare const VERSION_RECORD = "$version";
|
|
35
|
-
/** Every leaf under `schema`, by dotted path, in schema order.
|
|
54
|
+
/** Every leaf under `schema`, by dotted path, in schema order. A group's key
|
|
55
|
+
* is a segment; {@link prefSectionLeaves} is the walk for a section. */
|
|
36
56
|
declare function prefLeaves(schema: PrefGroup): Map<string, PrefLeaf>;
|
|
37
57
|
/** Each of `schema`'s leaves that `tree` holds a value for, as a path and
|
|
38
58
|
* that value — the inverse of building a tree from per-leaf records. */
|
|
@@ -44,11 +64,38 @@ declare function flattenPrefValues(schema: PrefGroup, tree: unknown): [string, u
|
|
|
44
64
|
*
|
|
45
65
|
* An empty or whitespace query matches everything, so a cleared field restores
|
|
46
66
|
* the tree rather than emptying it.
|
|
67
|
+
*
|
|
68
|
+
* An alias answers as the row it draws: its target's name and description
|
|
69
|
+
* where it gives none. `leafAt` finds that target, and defaults to looking in
|
|
70
|
+
* `node`; pass one over the whole schema when `node` is a part of it.
|
|
71
|
+
*/
|
|
72
|
+
declare function filterPrefSubtree<T extends PrefLeaf | PrefGroup>(node: T, query: string, path?: string, leafAt?: (path: string) => PrefLeaf | undefined): T | null;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The object a write to one field of an `object` leaf starts from: `held` itself where it is one. Where it is
|
|
76
|
+
* not, the write has to make a whole object, so it starts from the scalar lifted by the leaf's `fromScalar`, else
|
|
77
|
+
* from the leaf's `default`: one field on its own is a stroke with a width and no paint.
|
|
47
78
|
*/
|
|
48
|
-
declare function
|
|
79
|
+
declare function prefObjectBase(pref: PrefObject, held: unknown): Record<string, unknown>;
|
|
80
|
+
/** The object an `object` leaf holds after one of its fields is set: {@link prefObjectBase} with `key` at
|
|
81
|
+
* `value`, or without the key for `undefined`. */
|
|
82
|
+
declare function prefObjectWithField(pref: PrefObject, held: unknown, key: string, value: unknown): Record<string, unknown>;
|
|
49
83
|
|
|
50
|
-
/**
|
|
51
|
-
*
|
|
84
|
+
/**
|
|
85
|
+
* `leaf` as a named type: the same leaf carrying `name` in its `type` field.
|
|
86
|
+
* Declared once beside the code that reads its value and used wherever a
|
|
87
|
+
* schema wants one, spread with what that place sets for itself
|
|
88
|
+
* (`{ ...GradientStop, name: 'First stop' }`), or as a list's or a map's
|
|
89
|
+
* `item`. `name` is the identifier the type is exported under, which a schema
|
|
90
|
+
* editor prints in place of the leaf's literal.
|
|
91
|
+
*/
|
|
92
|
+
declare function prefType<L extends PrefLeaf>(name: string, leaf: L): L & {
|
|
93
|
+
type: string;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/** Takes stored values from one version to the next: rename, transform or
|
|
97
|
+
* delete entries in `records`, keyed by leaf path. It sees the values, not
|
|
98
|
+
* the stamps they are stored under, and only those at its own version. */
|
|
52
99
|
type PrefsMigration = (records: Map<string, unknown>) => void;
|
|
53
100
|
|
|
54
101
|
/** Decides what a stored value reads as for one kind of leaf: the value to
|
|
@@ -78,4 +125,29 @@ declare function openPrefsSync<S extends PrefGroup>(schema: S, options: PrefsOpt
|
|
|
78
125
|
storage: SyncStorageAdapter;
|
|
79
126
|
}): PrefsStore<S>;
|
|
80
127
|
|
|
81
|
-
|
|
128
|
+
/** What a surface has to know about a kind before it can lay its control out. */
|
|
129
|
+
interface PrefKindTraits {
|
|
130
|
+
/** Its value is made of other leaves' values: too much for one control on a
|
|
131
|
+
* line, so a bar opens it in a popover and a compact panel in a dialog. */
|
|
132
|
+
compound: boolean;
|
|
133
|
+
/** Its control is several controls, or a button. A row drawn as a `<label>`
|
|
134
|
+
* would hand a click on its text to the first of them. */
|
|
135
|
+
several: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The traits of every built-in kind. A `Record` over {@link PrefKind}, so a
|
|
139
|
+
* kind added to the union does not compile until it says what it is here:
|
|
140
|
+
* a plain set of kind names lets a new one through to draw inline in a
|
|
141
|
+
* `<label>`, on a bar's line, and with no dialog row.
|
|
142
|
+
*/
|
|
143
|
+
declare const PREF_KIND_TRAITS: Record<PrefKind, PrefKindTraits>;
|
|
144
|
+
/** Whether a leaf's value is made of other leaves' values. An app-defined kind is not: its renderer is one control. */
|
|
145
|
+
declare function prefIsCompound(leaf: {
|
|
146
|
+
kind: string;
|
|
147
|
+
}): boolean;
|
|
148
|
+
/** Whether a leaf's control is several controls or a button. */
|
|
149
|
+
declare function prefDrawsSeveral(leaf: {
|
|
150
|
+
kind: string;
|
|
151
|
+
}): boolean;
|
|
152
|
+
|
|
153
|
+
export { PREF_KIND_TRAITS, PrefGroup, PrefKind, type PrefKindTraits, PrefLeaf, PrefNumber, PrefObject, PrefSection, type PrefValidator, type PrefsMigration, type PrefsOptions, PrefsStore, VERSION_RECORD, filterPrefSubtree, flattenPrefValues, isPrefLeaf, isPrefSection, openPrefs, openPrefsSync, prefDisplayBounds, prefDrawsSeveral, prefHoldsValue, prefIsCompound, prefLeafAt, prefLeaves, prefObjectBase, prefObjectWithField, prefSectionLeaves, prefType, prefValueAtPath, repairPrefValue, visiblePrefSubtree };
|