@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
|
@@ -1,7 +1,117 @@
|
|
|
1
1
|
import { Display, UnitEntry, InfinityText, UnitSystem, Unit } from '@weasel-js/quantity';
|
|
2
2
|
|
|
3
|
+
/** What a {@link PrefAction}'s `run` is told. */
|
|
4
|
+
interface PrefActionContext {
|
|
5
|
+
/** The path the action sits at on the surface drawing it. */
|
|
6
|
+
path: string;
|
|
7
|
+
}
|
|
8
|
+
/** How a schema-driven UI should present an action leaf. */
|
|
9
|
+
type PrefActionControl = 'button' | 'icon';
|
|
10
|
+
/**
|
|
11
|
+
* A leaf that holds no value: a button among the rows or in a bar. A store
|
|
12
|
+
* neither reads nor writes one, and its path is not a {@link PrefPath}.
|
|
13
|
+
*
|
|
14
|
+
* It fires one of two things. `action` names an action the host registered,
|
|
15
|
+
* by key, which keeps the leaf plain data: it survives JSON, so a layout
|
|
16
|
+
* holding it can be saved and exported. `run` is code the schema carries.
|
|
17
|
+
* A leaf with both fires `action`. While a promise `run` returned is
|
|
18
|
+
* pending, the button is disabled.
|
|
19
|
+
*/
|
|
20
|
+
interface PrefAction extends PrefBase<'action', undefined> {
|
|
21
|
+
/** The key of a registered action to fire: its id, or `id:variant` for one
|
|
22
|
+
* variant of a parametric action. The leaf's `name` and `icon` are what
|
|
23
|
+
* the button shows, over the registered action's own. */
|
|
24
|
+
action?: string;
|
|
25
|
+
/** What to call when no `action` is named. */
|
|
26
|
+
run?: (ctx: PrefActionContext) => void | Promise<void>;
|
|
27
|
+
/** The button's text. Default: the leaf's `name`. */
|
|
28
|
+
label?: string;
|
|
29
|
+
/** `button` reads its label; `icon` is the icon alone, with the label in
|
|
30
|
+
* its tooltip. Unset: a button in a row, an icon in a bar. */
|
|
31
|
+
control?: PrefActionControl;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A second place for another leaf: its row draws that leaf's control and
|
|
36
|
+
* reads and writes that leaf's value, so one setting can sit on two pages.
|
|
37
|
+
* It holds no value of its own. A store neither reads nor writes one, and
|
|
38
|
+
* its path is not a {@link PrefPath}.
|
|
39
|
+
*
|
|
40
|
+
* `name` and `description` left empty are the target's.
|
|
41
|
+
*/
|
|
42
|
+
interface PrefAlias extends PrefBase<'alias', undefined> {
|
|
43
|
+
/** The leaf shown here, by the full path its value is read and written at (`'view.grid'`). */
|
|
44
|
+
of: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The leaf an alias stands for and the path its value lives at, following an
|
|
48
|
+
* alias of an alias to its end. `undefined` when a path along the way names
|
|
49
|
+
* no leaf, or the aliases lead back to one already passed.
|
|
50
|
+
*/
|
|
51
|
+
declare function prefAliasTarget(alias: PrefAlias, leafAt: (path: string) => PrefLeaf | undefined): {
|
|
52
|
+
path: string;
|
|
53
|
+
leaf: PrefLeaf;
|
|
54
|
+
} | undefined;
|
|
55
|
+
/** A leaf drawn through an alias: the target, under the alias's own name and description where it gives them. */
|
|
56
|
+
declare function prefAliasedLeaf(alias: PrefAlias, target: PrefLeaf): PrefLeaf;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A line of text among the rows, holding no value: `name` is the line and
|
|
60
|
+
* `description` the note under it. A store neither reads nor writes one, and
|
|
61
|
+
* its path is not a {@link PrefPath}.
|
|
62
|
+
*/
|
|
63
|
+
type PrefLabel = PrefBase<'label', undefined>;
|
|
64
|
+
/** A rule drawn between the rows, holding no value and drawing none of its own text. */
|
|
65
|
+
type PrefSeparator = PrefBase<'separator', undefined>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A leaf whose value is an array, every entry described by `item`.
|
|
69
|
+
*
|
|
70
|
+
* `item` is an ordinary leaf, built-in or app-defined, so a list of objects,
|
|
71
|
+
* of lists or of a custom kind is declared the way a list of numbers is, and
|
|
72
|
+
* each entry is validated and drawn as that leaf would be on its own. Its
|
|
73
|
+
* `default` is what a new entry starts as, and its `name` names one entry
|
|
74
|
+
* (`'Phase'` under a list named `'Phases'`).
|
|
75
|
+
*/
|
|
76
|
+
interface PrefList extends PrefBase<'list', readonly unknown[]> {
|
|
77
|
+
item: PrefLeaf;
|
|
78
|
+
/** A stored list shorter than this reads as the default, and a UI stops removing at it. */
|
|
79
|
+
minItems?: number;
|
|
80
|
+
/** A stored list longer than this reads cut to it, and a UI stops adding at it. */
|
|
81
|
+
maxItems?: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* A leaf whose value is an object keyed by strings nobody declared, every
|
|
86
|
+
* value described by `item`: the keyed counterpart of a {@link PrefList}.
|
|
87
|
+
* `item` is an ordinary leaf of any kind; its `default` is what a new entry
|
|
88
|
+
* starts as, and its `name` names one entry's value.
|
|
89
|
+
*/
|
|
90
|
+
interface PrefMap extends PrefBase<'map', Readonly<Record<string, unknown>>> {
|
|
91
|
+
item: PrefLeaf;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* A leaf whose value is one of several object shapes, told apart by the
|
|
96
|
+
* string its `tag` field holds: `{ type: 'linear', angle: 90 }` or
|
|
97
|
+
* `{ type: 'radial', radius: 1 }` under `tag: 'type'`.
|
|
98
|
+
*
|
|
99
|
+
* Each variant is an `object` leaf keyed by its tag value. Its `children`
|
|
100
|
+
* are the fields beside the tag, its `name` is what a person chooses, and
|
|
101
|
+
* its `default` (without the tag) is what the value becomes when they choose
|
|
102
|
+
* it. A stored value whose tag names no variant reads as the leaf's default.
|
|
103
|
+
*/
|
|
104
|
+
interface PrefUnion extends PrefBase<'union', unknown> {
|
|
105
|
+
tag: string;
|
|
106
|
+
variants: Record<string, PrefObject>;
|
|
107
|
+
}
|
|
108
|
+
/** The variant `value` is, or `undefined` when its tag names none. */
|
|
109
|
+
declare function prefVariantOf(leaf: PrefUnion, value: unknown): [key: string, variant: PrefObject] | undefined;
|
|
110
|
+
/** The value a union takes on switching to the variant at `key`: that variant's default, tagged. */
|
|
111
|
+
declare function prefVariantDefault(leaf: PrefUnion, key: string): Record<string, unknown>;
|
|
112
|
+
|
|
3
113
|
/** The value types a built-in pref leaf can hold. */
|
|
4
|
-
type PrefKind = 'number' | 'boolean' | 'string' | 'enum' | 'color' | 'paint' | 'object' | 'field';
|
|
114
|
+
type PrefKind = 'number' | 'boolean' | 'string' | 'enum' | 'color' | 'paint' | 'object' | 'list' | 'map' | 'union' | 'field' | 'action' | 'alias' | 'label' | 'separator';
|
|
5
115
|
/**
|
|
6
116
|
* Leaves that share one row in a compact property UI (weasel-ui
|
|
7
117
|
* `SelectionPanel`, labkit's `ControlPanel`), declared on the first of them.
|
|
@@ -26,6 +136,13 @@ interface PrefBase<K extends string, Value> {
|
|
|
26
136
|
default: Value;
|
|
27
137
|
/** Hide from a host app's settings UI by default. */
|
|
28
138
|
hidden?: boolean;
|
|
139
|
+
/** Nothing held where this leaf's value is read means `default`, because
|
|
140
|
+
* whoever reads the value takes it that way (`pose.rotation ?? 0`). A
|
|
141
|
+
* surface over sparse settings reads every leaf so already. One over a
|
|
142
|
+
* scene node, where a missing key otherwise means the node has no such
|
|
143
|
+
* property, shows the default only for a leaf that says this, and still
|
|
144
|
+
* writes nothing until an edit. */
|
|
145
|
+
absentIsDefault?: boolean;
|
|
29
146
|
/** Render full-width with no label row in schema-driven settings UIs
|
|
30
147
|
* (weasel-ui `PrefsForm` honors this for leaves whose control brings
|
|
31
148
|
* its own chrome). */
|
|
@@ -43,6 +160,19 @@ interface PrefBase<K extends string, Value> {
|
|
|
43
160
|
* shows the longest of them that fits. `name` stays the accessible name, so
|
|
44
161
|
* these abbreviate without costing anything. */
|
|
45
162
|
short?: readonly string[];
|
|
163
|
+
/** Never auto. A surface that lets a leaf be left for its owner to decide
|
|
164
|
+
* (weasel-ui `PrefsForm`'s `onAutoChange`, labkit's `ControlPanel`) gives
|
|
165
|
+
* this one no way to. */
|
|
166
|
+
manual?: boolean;
|
|
167
|
+
/** Starts auto, where it would start pinned at `default`. */
|
|
168
|
+
unpinned?: boolean;
|
|
169
|
+
/** What the leaf reads while it is auto, where its owner computes nothing
|
|
170
|
+
* for it. Unset, an auto leaf has no value. */
|
|
171
|
+
autoValue?: Value;
|
|
172
|
+
/** The name of the type this leaf was made from, set by `prefType`. A
|
|
173
|
+
* schema editor shows such a leaf as one closed thing and prints the name
|
|
174
|
+
* in place of its literal. */
|
|
175
|
+
type?: string;
|
|
46
176
|
}
|
|
47
177
|
/** How a schema-driven UI should present a number pref. */
|
|
48
178
|
type PrefNumberControl = 'input' | 'slider';
|
|
@@ -51,7 +181,7 @@ type PrefBooleanControl = 'checkbox' | 'switch' | 'toggle';
|
|
|
51
181
|
/** How a schema-driven UI should present a string pref. */
|
|
52
182
|
type PrefStringControl = 'input' | 'textarea';
|
|
53
183
|
/** How a schema-driven UI should present an enum pref. */
|
|
54
|
-
type PrefEnumControl = 'select' | 'radio' | 'toggle';
|
|
184
|
+
type PrefEnumControl = 'select' | 'radio' | 'toggle' | 'menu';
|
|
55
185
|
/** Display-unit conversion for number leaves whose stored value uses a
|
|
56
186
|
* canonical unit the user shouldn't see (e.g. radians stored, degrees
|
|
57
187
|
* shown). The stored value stays canonical; UIs convert at the edge. */
|
|
@@ -89,7 +219,7 @@ interface PrefNumber extends PrefBase<'number', number> {
|
|
|
89
219
|
* reads `2.00M`. Presentation only: the stored value stays a number. */
|
|
90
220
|
display?: Display;
|
|
91
221
|
unit?: PrefNumberUnit;
|
|
92
|
-
/** Which end of a slider
|
|
222
|
+
/** Which end of a slider gets a stop for ±Infinity, one step beyond the range. */
|
|
93
223
|
endless?: 'min' | 'max' | 'both';
|
|
94
224
|
/** The word infinity shows as — `'never'`, `'uncapped'`. Default `∞`. */
|
|
95
225
|
infinity?: InfinityText;
|
|
@@ -136,16 +266,8 @@ interface PrefEnumEncoding<T extends string = string> {
|
|
|
136
266
|
/** What to store for `option`. `undefined` removes the field. */
|
|
137
267
|
write: (option: T, siblings: Record<string, unknown> | undefined) => unknown;
|
|
138
268
|
}
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
interface PrefEnum<T extends string = string> extends PrefBase<'enum', T | undefined> {
|
|
142
|
-
/**
|
|
143
|
-
* The field may hold none of the options, and that absence is a state of
|
|
144
|
-
* its own rather than a missing value — a script that is neither super nor
|
|
145
|
-
* sub. A toggle control then lets the chosen segment be clicked off, which
|
|
146
|
-
* removes the field.
|
|
147
|
-
*/
|
|
148
|
-
clearable?: boolean;
|
|
269
|
+
/** What every enum leaf carries; {@link PrefEnum} adds `clearable`. */
|
|
270
|
+
interface PrefEnumBase<T extends string = string> extends PrefBase<'enum', T | undefined> {
|
|
149
271
|
/** `short` holds shorter forms of `label`, longest first, for a segmented
|
|
150
272
|
* control too narrow for the full one — down to a capital or two. `icon`
|
|
151
273
|
* names a glyph in the host UI's set (weasel-ui resolves it against
|
|
@@ -168,6 +290,22 @@ interface PrefEnum<T extends string = string> extends PrefBase<'enum', T | undef
|
|
|
168
290
|
control?: PrefEnumControl;
|
|
169
291
|
encoding?: PrefEnumEncoding<T>;
|
|
170
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* A pref with a fixed set of labeled choices.
|
|
295
|
+
*
|
|
296
|
+
* `clearable` says the field may hold none of the options, and that absence
|
|
297
|
+
* is a state of its own rather than a missing value — a script that is
|
|
298
|
+
* neither super nor sub. A toggle control then lets the chosen segment be
|
|
299
|
+
* clicked off, which removes the field. Such a leaf's `default` is
|
|
300
|
+
* `undefined`: a missing value is the only stored form of cleared, so a
|
|
301
|
+
* default would bring an option back the moment the field was cleared.
|
|
302
|
+
*/
|
|
303
|
+
type PrefEnum<T extends string = string> = PrefEnumBase<T> & ({
|
|
304
|
+
clearable?: false;
|
|
305
|
+
} | {
|
|
306
|
+
clearable: true;
|
|
307
|
+
default: undefined;
|
|
308
|
+
});
|
|
171
309
|
/** A single color, stored as a hex string. For a value that may also be a
|
|
172
310
|
* gradient or a pattern, use {@link PrefPaint} instead. */
|
|
173
311
|
interface PrefColor extends PrefBase<'color', string> {
|
|
@@ -209,19 +347,18 @@ interface PrefPaint extends PrefBase<'paint', unknown> {
|
|
|
209
347
|
*
|
|
210
348
|
* `children` paths are relative to the object. They are ordinary leaves, so a
|
|
211
349
|
* field that is itself a union (a stroke's `paint`) declares the kind that
|
|
212
|
-
* edits that union. A child may also be a {@link
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* lists.
|
|
350
|
+
* edits that union. A child may also be a {@link PrefSection}, which
|
|
351
|
+
* organizes the fields under a heading without contributing to the path. A
|
|
352
|
+
* `TextStyle` needs it: its character and paragraph fields belong to one
|
|
353
|
+
* value but read as two lists.
|
|
217
354
|
*/
|
|
218
355
|
interface PrefObject extends PrefBase<'object', unknown> {
|
|
219
|
-
children: Record<string, PrefLeaf |
|
|
356
|
+
children: Record<string, PrefLeaf | PrefSection>;
|
|
220
357
|
/**
|
|
221
358
|
* Lift a non-object value into the object form, for a consumer field that
|
|
222
359
|
* may also be held as a scalar. Called before a child edit is applied;
|
|
223
|
-
* without it a scalar-valued leaf shows its children empty and
|
|
224
|
-
*
|
|
360
|
+
* without it a scalar-valued leaf shows its children empty, and an edit
|
|
361
|
+
* starts from the leaf's `default`.
|
|
225
362
|
*/
|
|
226
363
|
fromScalar?: (value: unknown) => Record<string, unknown>;
|
|
227
364
|
}
|
|
@@ -236,7 +373,7 @@ interface PrefField extends PrefBase<'field', string> {
|
|
|
236
373
|
}
|
|
237
374
|
/** One built-in pref leaf. `PrefLeaf` widens this to include
|
|
238
375
|
* app-defined kinds. */
|
|
239
|
-
type BuiltinPref = PrefNumber | PrefBoolean | PrefString | PrefEnum | PrefColor | PrefPaint | PrefObject | PrefField;
|
|
376
|
+
type BuiltinPref = PrefNumber | PrefBoolean | PrefString | PrefEnum | PrefColor | PrefPaint | PrefObject | PrefList | PrefMap | PrefUnion | PrefField | PrefAction | PrefAlias | PrefLabel | PrefSeparator;
|
|
240
377
|
/**
|
|
241
378
|
* The built-in kinds, as a table. A kind added to {@link PrefKind} is a
|
|
242
379
|
* compile error here, and from here it is one in every renderer's `never`
|
|
@@ -261,27 +398,71 @@ declare function pairRowsOf(leaves: Iterable<readonly [path: string, leaf: PrefL
|
|
|
261
398
|
declare function isBuiltinPref(leaf: PrefLeaf): leaf is BuiltinPref;
|
|
262
399
|
/** Built-in or app-defined leaf. */
|
|
263
400
|
type PrefLeaf = BuiltinPref | PrefCustom;
|
|
264
|
-
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* How a {@link PrefGroup} is drawn: `page` gets an entry in a form's rail and
|
|
404
|
+
* a pane of its own; `tab` shares a tab strip with the `tab` groups beside it;
|
|
405
|
+
* `panel` is a bordered, titled box; `section` is a heading over its rows;
|
|
406
|
+
* `fragment` draws nothing of its own, so its rows sit among its neighbors'
|
|
407
|
+
* as though they were written there. A fragment exists to hold things
|
|
408
|
+
* together: one key for their values to nest under, one node to move.
|
|
409
|
+
*/
|
|
410
|
+
type PrefGroupAs = 'page' | 'tab' | 'panel' | 'section' | 'fragment' | 'bar';
|
|
411
|
+
/** How a {@link PrefSection} is drawn. */
|
|
412
|
+
type PrefSectionAs = Exclude<PrefGroupAs, 'page'>;
|
|
413
|
+
/**
|
|
414
|
+
* A group whose key is a path segment: `view` > `gridDensity` is the leaf at
|
|
415
|
+
* `view.gridDensity`, and its value nests the same way. The shape of a
|
|
416
|
+
* preferences schema — what `openPrefs` stores, `PrefsForm` renders, and a
|
|
417
|
+
* tool declares its options as. A key holds no `.`.
|
|
418
|
+
*/
|
|
265
419
|
interface PrefGroup {
|
|
266
420
|
/** Heading for the group's rows. **Empty means no heading** — for a group
|
|
267
|
-
* that exists to
|
|
421
|
+
* that exists to organize, not to name: one whose children are themselves
|
|
268
422
|
* groups carrying the labels a reader needs. Give it a name whenever the
|
|
269
423
|
* name is the referent (a `Border` group over `Top` / `Right` / `Bottom`
|
|
270
424
|
* reads as nothing without it). */
|
|
271
425
|
name: string;
|
|
272
426
|
description?: string;
|
|
427
|
+
/** How the group is drawn. Unset, its depth decides: a top-level group is a
|
|
428
|
+
* `page`, and one inside another is a `section`. */
|
|
429
|
+
as?: PrefGroupAs;
|
|
273
430
|
children: Record<string, PrefLeaf | PrefGroup>;
|
|
274
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* A heading over leaves that adds nothing to their paths: each member is
|
|
434
|
+
* addressed by its own key alone, and the section's key only identifies the
|
|
435
|
+
* section. The shape of a node's property schema, where a leaf's key is the
|
|
436
|
+
* whole dotted node path (`pose.x`, `data.fill`), and of the headings inside
|
|
437
|
+
* a {@link PrefObject}, where a key is relative to the object.
|
|
438
|
+
*/
|
|
439
|
+
interface PrefSection {
|
|
440
|
+
/** Heading for the section's rows. Empty means no heading, as for a
|
|
441
|
+
* {@link PrefGroup}. */
|
|
442
|
+
name: string;
|
|
443
|
+
description?: string;
|
|
444
|
+
/** How the section is drawn, as a {@link PrefGroup}'s `as` — without
|
|
445
|
+
* `page`, since nothing that draws sections has a rail. Unset: a heading
|
|
446
|
+
* over its rows. */
|
|
447
|
+
as?: PrefSectionAs;
|
|
448
|
+
members: Record<string, PrefLeaf | PrefSection>;
|
|
449
|
+
}
|
|
450
|
+
/** Whether a top-level group gets a page of its own, and not a place on the page of the root's own leaves. */
|
|
451
|
+
declare function prefGroupIsPage(group: PrefGroup): boolean;
|
|
275
452
|
|
|
276
453
|
type Join<A extends string, B extends string> = A extends '' ? B : `${A}.${B}`;
|
|
277
|
-
/** Every
|
|
278
|
-
* `object` leaf is one path, its fields are not
|
|
454
|
+
/** Every value's dotted path in a `PrefGroup` schema, where a group's key is a
|
|
455
|
+
* segment; an `object` leaf is one path, its fields are not, and an `action`,
|
|
456
|
+
* `alias`, `label`, or `separator` leaf, holding no value, has none. A `PrefSection`
|
|
457
|
+
* has no such paths: each of its leaves is addressed by its own key. */
|
|
279
458
|
type PrefPath<G, Prefix extends string = ''> = G extends {
|
|
280
459
|
children: infer C;
|
|
281
460
|
} ? string extends keyof C ? Join<Prefix, string> : {
|
|
282
461
|
[K in keyof C & string]: C[K] extends {
|
|
283
462
|
kind: string;
|
|
284
|
-
} ?
|
|
463
|
+
} ? C[K] extends {
|
|
464
|
+
kind: 'action' | 'alias' | 'label' | 'separator';
|
|
465
|
+
} ? never : Join<Prefix, K> : C[K] extends {
|
|
285
466
|
children: Record<string, unknown>;
|
|
286
467
|
} ? PrefPath<C[K], Join<Prefix, K>> : never;
|
|
287
468
|
}[keyof C & string] : never;
|
|
@@ -293,8 +474,22 @@ type PrefAtPath<G, P extends string> = G extends {
|
|
|
293
474
|
} ? never : PrefAtPath<C[H], Rest> : never : P extends keyof C ? C[P] extends {
|
|
294
475
|
kind: string;
|
|
295
476
|
} ? C[P] : never : never : never;
|
|
477
|
+
type AllOf<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
478
|
+
/** The fields an `object` leaf's `children` describe, sections folded in. Each is optional: an object may omit any. */
|
|
479
|
+
type PrefFieldsOf<C> = {
|
|
480
|
+
[K in keyof C as C[K] extends {
|
|
481
|
+
kind: string;
|
|
482
|
+
} ? K : never]?: PrefValueOf<C[K]>;
|
|
483
|
+
} & AllOf<{
|
|
484
|
+
[K in keyof C]: C[K] extends {
|
|
485
|
+
members: infer M;
|
|
486
|
+
} ? PrefFieldsOf<M> : never;
|
|
487
|
+
}[keyof C]>;
|
|
296
488
|
/** What a leaf holds: its kind's value type for a built-in kind, the type of
|
|
297
|
-
* its `default` for an app-defined one.
|
|
489
|
+
* its `default` for an app-defined one. A list holds an array of what its
|
|
490
|
+
* `item` holds, a map a record of it, and a union one variant's fields
|
|
491
|
+
* under that variant's tag — where the schema keeps `tag` a literal
|
|
492
|
+
* (`tag: 'type' as const`); one widened to `string` is typed by its default. */
|
|
298
493
|
type PrefValueOf<L> = L extends {
|
|
299
494
|
kind: 'number';
|
|
300
495
|
} ? number : L extends {
|
|
@@ -311,6 +506,23 @@ type PrefValueOf<L> = L extends {
|
|
|
311
506
|
} ? L extends {
|
|
312
507
|
clearable: true;
|
|
313
508
|
} ? T | undefined : T : L extends {
|
|
509
|
+
kind: 'list';
|
|
510
|
+
item: infer I;
|
|
511
|
+
} ? PrefValueOf<I>[] : L extends {
|
|
512
|
+
kind: 'map';
|
|
513
|
+
item: infer I;
|
|
514
|
+
} ? Record<string, PrefValueOf<I>> : L extends {
|
|
515
|
+
kind: 'union';
|
|
516
|
+
tag: infer T extends string;
|
|
517
|
+
variants: infer V;
|
|
518
|
+
default: infer D;
|
|
519
|
+
} ? string extends keyof V | T ? D : {
|
|
520
|
+
[K in keyof V & string]: {
|
|
521
|
+
[P in T]: K;
|
|
522
|
+
} & (V[K] extends {
|
|
523
|
+
children: infer C;
|
|
524
|
+
} ? PrefFieldsOf<C> : unknown);
|
|
525
|
+
}[keyof V & string] : L extends {
|
|
314
526
|
default: infer D;
|
|
315
527
|
} ? D : unknown;
|
|
316
528
|
/** What the leaf at `P` holds. */
|
|
@@ -342,12 +554,19 @@ interface PrefsStore<S extends PrefGroup> {
|
|
|
342
554
|
stored(): Record<string, unknown>;
|
|
343
555
|
/** `changes` is empty when only records no leaf describes changed. */
|
|
344
556
|
subscribe(listener: (changes: PrefChange[]) => void): () => void;
|
|
345
|
-
/** False
|
|
346
|
-
* by a newer schema. Changes still apply for this session
|
|
557
|
+
/** False while the store cannot persist: storage has not been read yet, or
|
|
558
|
+
* was written by a newer schema. Changes still apply for this session, and
|
|
559
|
+
* ones made before a late read lands are persisted when it does. */
|
|
347
560
|
readonly writable: boolean;
|
|
561
|
+
/** Try again now to read storage that could not be read at open, ahead of
|
|
562
|
+
* the store's own retries. Resolves whether storage has been read. */
|
|
563
|
+
read(): Promise<boolean>;
|
|
564
|
+
/** Resolves once storage has been read: at once for a store that opened
|
|
565
|
+
* with its values, and when a later read lands for one that could not. */
|
|
566
|
+
whenRead(): Promise<void>;
|
|
348
567
|
/** Resolves true when every queued write reached storage. */
|
|
349
568
|
flush(): Promise<boolean>;
|
|
350
569
|
close(): Promise<void>;
|
|
351
570
|
}
|
|
352
571
|
|
|
353
|
-
export { type
|
|
572
|
+
export { type PrefList as A, type BuiltinPref as B, type PrefMap as C, type PrefNumberControl as D, type PrefNumberUnit as E, type PrefPaint as F, type PrefPair as G, type PrefPath as H, type PrefSectionAs as I, type PrefSeparator as J, type PrefString as K, type PrefStringControl as L, type PrefUnion as M, type PrefValueAt as N, type PrefValueOf as O, type PrefLeaf as P, isBuiltinPref as Q, pairRowsOf as R, prefAliasTarget as S, prefAliasedLeaf as T, prefGroupIsPage as U, prefUnit as V, prefVariantDefault as W, prefVariantOf as X, type PrefGroup as a, type PrefSection as b, type PrefNumber as c, type PrefObject as d, type PrefsStore as e, type PrefKind as f, PREF_KINDS as g, type PrefAction as h, type PrefActionContext as i, type PrefActionControl as j, type PrefAlias as k, type PrefAtPath as l, type PrefBase as m, type PrefBoolean as n, type PrefBooleanControl as o, type PrefBooleanEncoding as p, type PrefChange as q, type PrefColor as r, type PrefCustom as s, type PrefEnum as t, type PrefEnumBase as u, type PrefEnumControl as v, type PrefEnumEncoding as w, type PrefField as x, type PrefGroupAs as y, type PrefLabel as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weasel-js/prefs",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.4",
|
|
4
4
|
"description": "A preferences schema, a store that loads, validates, migrates and persists values against it, and React hooks over the store.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -41,8 +41,9 @@
|
|
|
41
41
|
"build": "tsup"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@weasel-js/quantity": "1.9.
|
|
45
|
-
"@weasel-js/
|
|
44
|
+
"@weasel-js/quantity": "1.9.4",
|
|
45
|
+
"@weasel-js/registry": "1.9.4",
|
|
46
|
+
"@weasel-js/storage": "1.9.4"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
49
|
"react": ">=18"
|