@weasel-js/prefs 1.10.1 → 1.11.0
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 +51 -0
- package/dist/chunk-OZFER7VN.js +706 -0
- package/dist/chunk-OZFER7VN.js.map +1 -0
- package/dist/{chunk-ASSX3JHY.js → chunk-WN6QQICK.js} +27 -589
- package/dist/chunk-WN6QQICK.js.map +1 -0
- package/dist/chunk-ZLXZRX73.js +32 -0
- package/dist/chunk-ZLXZRX73.js.map +1 -0
- package/dist/css-v-LpmTll.d.ts +49 -0
- package/dist/{open-C83pU7Va.d.ts → groups-BDZC-ywb.d.ts} +115 -229
- package/dist/index.d.ts +51 -53
- package/dist/index.js +60 -103
- package/dist/index.js.map +1 -1
- package/dist/open-VJ1zlFJz.d.ts +203 -0
- package/dist/react.d.ts +27 -4
- package/dist/react.js +75 -3
- package/dist/react.js.map +1 -1
- package/dist/vite.d.ts +23 -0
- package/dist/vite.js +61 -0
- package/dist/vite.js.map +1 -0
- package/package.json +16 -6
- package/dist/chunk-ASSX3JHY.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { UnitEntry, UnitSystem, Unit, Display, InfinityText } from '@weasel-js/quantity';
|
|
1
|
+
import { IconRef } from '@weasel-js/icons';
|
|
2
|
+
import { UnitEntry, UnitSystem, Unit, UnitTable, Display, InfinityText } from '@weasel-js/quantity';
|
|
3
3
|
|
|
4
4
|
/** What a condition can compare a leaf's value against. `null` stands for
|
|
5
5
|
* nothing held: a missing value as well as a stored `null`. */
|
|
@@ -107,6 +107,16 @@ interface PrefAction extends PrefBase<'action', undefined> {
|
|
|
107
107
|
* its tooltip. Unset: a button in a row, an icon in a bar. */
|
|
108
108
|
control?: PrefActionControl;
|
|
109
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Every action the host registered in the action group `group`, in registry
|
|
112
|
+
* order, each drawn as an {@link PrefAction} naming it would be: an action
|
|
113
|
+
* registered later appears without the schema changing. Holds no value, as
|
|
114
|
+
* an `action` holds none.
|
|
115
|
+
*/
|
|
116
|
+
interface PrefActions extends PrefBase<'actions', undefined> {
|
|
117
|
+
/** The registry action group whose actions are drawn. */
|
|
118
|
+
group: string;
|
|
119
|
+
}
|
|
110
120
|
|
|
111
121
|
/**
|
|
112
122
|
* A second place for another leaf: its row draws that leaf's control and
|
|
@@ -135,9 +145,24 @@ declare function prefAliasTarget(alias: PrefAlias, leafAt: (path: string) => Pre
|
|
|
135
145
|
* nothing.
|
|
136
146
|
*/
|
|
137
147
|
declare function prefAliasName(alias: PrefAlias, target?: PrefLeaf): string;
|
|
138
|
-
/** A leaf drawn through an alias: the target, under the alias's own name and
|
|
148
|
+
/** A leaf drawn through an alias: the target, under the alias's own name, description and access letter where it gives them. */
|
|
139
149
|
declare function prefAliasedLeaf(alias: PrefAlias, target: PrefLeaf): PrefLeaf;
|
|
140
150
|
|
|
151
|
+
/** Reads a value held beside a number leaf, by the path a condition there would name. */
|
|
152
|
+
type PrefBoundReader = (path: string) => unknown;
|
|
153
|
+
/**
|
|
154
|
+
* A number leaf's bound where its value is held: `undefined` for none. Asked
|
|
155
|
+
* per holder, so each scene node a panel edits can have its own.
|
|
156
|
+
*/
|
|
157
|
+
type PrefBoundAt = (read: PrefBoundReader) => number | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* `leaf` with its `minAt` and `maxAt` read against `read` and folded into
|
|
160
|
+
* `min` and `max`, whichever is tighter. The leaf itself when it has neither.
|
|
161
|
+
*/
|
|
162
|
+
declare function prefNumberAt(leaf: PrefNumber, read: PrefBoundReader): PrefNumber;
|
|
163
|
+
/** `n` held to `leaf`'s `min` and `max`, except an infinity an `endless` end stands for. */
|
|
164
|
+
declare function prefClampNumber(leaf: PrefNumber, n: number): number;
|
|
165
|
+
|
|
141
166
|
/**
|
|
142
167
|
* A line of text among the rows, holding no value: `name` is the line and
|
|
143
168
|
* `description` the note under it. A store neither reads nor writes one, and
|
|
@@ -156,7 +181,7 @@ type PrefSeparator = PrefBase<'separator', undefined>;
|
|
|
156
181
|
* `default` is what a new entry starts as, and its `name` names one entry
|
|
157
182
|
* (`'Phase'` under a list named `'Phases'`).
|
|
158
183
|
*/
|
|
159
|
-
interface PrefList extends
|
|
184
|
+
interface PrefList extends PrefValueBase<'list', readonly unknown[]> {
|
|
160
185
|
item: PrefLeaf;
|
|
161
186
|
/** A stored list shorter than this reads as the default, and a UI stops removing at it. */
|
|
162
187
|
minItems?: number;
|
|
@@ -197,7 +222,7 @@ declare function locusSelectors(stored: unknown): Set<string>;
|
|
|
197
222
|
* `item` is an ordinary leaf of any kind; its `default` is what a new entry
|
|
198
223
|
* starts as, and its `name` names one entry's value.
|
|
199
224
|
*/
|
|
200
|
-
interface PrefMap extends
|
|
225
|
+
interface PrefMap extends PrefValueBase<'map', Readonly<Record<string, unknown>>> {
|
|
201
226
|
item: PrefLeaf;
|
|
202
227
|
}
|
|
203
228
|
|
|
@@ -211,7 +236,8 @@ interface PrefMap extends PrefBase<'map', Readonly<Record<string, unknown>>> {
|
|
|
211
236
|
* its `default` (without the tag) is what the value becomes when they choose
|
|
212
237
|
* it. A stored value whose tag names no variant reads as the leaf's default.
|
|
213
238
|
*/
|
|
214
|
-
interface PrefUnion extends
|
|
239
|
+
interface PrefUnion extends PrefValueBase<'union', unknown> {
|
|
240
|
+
/** The field of the value that names its variant. Not one of `tags`. */
|
|
215
241
|
tag: string;
|
|
216
242
|
variants: Record<string, PrefObject>;
|
|
217
243
|
}
|
|
@@ -261,6 +287,9 @@ type PrefNumberUnit = PrefLinearUnit | PrefFunctionUnit;
|
|
|
261
287
|
interface ResolvedPrefUnit extends PrefFunctionUnit {
|
|
262
288
|
format: (stored: number) => string;
|
|
263
289
|
}
|
|
290
|
+
/** What a unit leaf's field reads as typed text: its `accepts` table, and its
|
|
291
|
+
* `suffix` as the display unit itself. */
|
|
292
|
+
declare function prefUnitAccepts(unit: PrefNumberUnit): Readonly<UnitTable>;
|
|
264
293
|
/** Whether `unit` is the data form, and so can be written out and edited. */
|
|
265
294
|
declare function isPrefLinearUnit(unit: PrefNumberUnit): unit is PrefLinearUnit;
|
|
266
295
|
/** How to convert and format with `unit`, whichever form it was written in. */
|
|
@@ -278,7 +307,7 @@ declare function prefUnit(system: UnitSystem, display: Unit, opts?: {
|
|
|
278
307
|
}): PrefLinearUnit;
|
|
279
308
|
|
|
280
309
|
/** The value types a built-in pref leaf can hold. */
|
|
281
|
-
type PrefKind = 'number' | 'boolean' | 'string' | 'enum' | 'color' | 'paint' | 'object' | 'list' | 'map' | 'union' | 'field' | 'action' | 'alias' | 'label' | 'separator';
|
|
310
|
+
type PrefKind = 'number' | 'boolean' | 'string' | 'enum' | 'color' | 'paint' | 'object' | 'list' | 'map' | 'union' | 'field' | 'action' | 'actions' | 'alias' | 'label' | 'separator';
|
|
282
311
|
/** Leaves that share one row in a compact property UI, declared on the first
|
|
283
312
|
* of them. Purely presentational. */
|
|
284
313
|
interface PrefPair {
|
|
@@ -298,6 +327,14 @@ interface PrefBase<K extends string, Value> {
|
|
|
298
327
|
description: string;
|
|
299
328
|
/** Fallback when nothing is persisted. */
|
|
300
329
|
default: Value;
|
|
330
|
+
/** Words the leaf is also found by and gathered under: a settings search
|
|
331
|
+
* matches them as it matches `name`, and `prefLeavesTagged` gathers every
|
|
332
|
+
* leaf carrying one. A leaf also carries the tags of every group above it
|
|
333
|
+
* (`prefLeafTags`). Unrelated to a union leaf's `tag`, which names the
|
|
334
|
+
* field its value's variant is read from. */
|
|
335
|
+
tags?: readonly string[];
|
|
336
|
+
/** The letter that picks this in a menu, and with the menu bar's chord opens a top-level menu. One character; supported, never required. */
|
|
337
|
+
access?: string;
|
|
301
338
|
/** Hide from a host app's settings UI by default. */
|
|
302
339
|
hidden?: boolean;
|
|
303
340
|
/** Drawn only while this holds. Presentational: the value stays stored
|
|
@@ -321,12 +358,11 @@ interface PrefBase<K extends string, Value> {
|
|
|
321
358
|
* fits there (`prefFitsHeading`); any other leaf stays a row. Honored by
|
|
322
359
|
* weasel-ui `PrefsForm` and labkit's `ControlPanel`. */
|
|
323
360
|
heading?: boolean;
|
|
324
|
-
/** Glyph naming this leaf
|
|
325
|
-
*
|
|
326
|
-
* icon set and cannot depend on one. Read where a leaf's `name` has nowhere to go — a
|
|
361
|
+
/** Glyph naming this leaf. A name from `@weasel-js/icons`; this package draws
|
|
362
|
+
* nothing. Read where a leaf's `name` has nowhere to go — a
|
|
327
363
|
* `pair`ed row is labeled by the pair, so its fields have only the glyph
|
|
328
364
|
* to tell them apart. */
|
|
329
|
-
icon?:
|
|
365
|
+
icon?: IconRef;
|
|
330
366
|
/** Puts this leaf and the ones it names on one row. */
|
|
331
367
|
pair?: PrefPair;
|
|
332
368
|
/** Shorter forms of `name`, longest first. A surface short of room for
|
|
@@ -361,6 +397,11 @@ interface PrefBase<K extends string, Value> {
|
|
|
361
397
|
* what the leaf's value type is read from. */
|
|
362
398
|
defaultLocus?: PrefLocus;
|
|
363
399
|
}
|
|
400
|
+
/** The fields every leaf holding a value shares, besides {@link PrefBase}'s. */
|
|
401
|
+
interface PrefValueBase<K extends string, Value> extends PrefBase<K, Value> {
|
|
402
|
+
/** Drawn showing its value but not editable. */
|
|
403
|
+
readout?: boolean;
|
|
404
|
+
}
|
|
364
405
|
/** How a schema-driven UI should present a number pref. */
|
|
365
406
|
type PrefNumberControl = 'input' | 'slider';
|
|
366
407
|
/** How a schema-driven UI should present a boolean pref. */
|
|
@@ -369,11 +410,16 @@ type PrefBooleanControl = 'checkbox' | 'switch' | 'toggle';
|
|
|
369
410
|
type PrefStringControl = 'input' | 'textarea';
|
|
370
411
|
/** How a schema-driven UI should present an enum pref. */
|
|
371
412
|
type PrefEnumControl = 'select' | 'radio' | 'toggle' | 'menu';
|
|
372
|
-
/**
|
|
373
|
-
|
|
374
|
-
interface PrefNumber extends PrefBase<'number', number> {
|
|
413
|
+
/** What every number leaf carries; {@link PrefNumber} adds `clearable`. */
|
|
414
|
+
interface PrefNumberBase extends PrefValueBase<'number', number | undefined> {
|
|
375
415
|
min?: number;
|
|
376
416
|
max?: number;
|
|
417
|
+
/** A lower bound read from where the value is held — a scene node's own
|
|
418
|
+
* minimum — taken with `min`, the larger winning. A surface resolves it
|
|
419
|
+
* per holder with `prefNumberAt`. */
|
|
420
|
+
minAt?: PrefBoundAt;
|
|
421
|
+
/** The upper counterpart of `minAt`, taken with `max`, the smaller winning. */
|
|
422
|
+
maxAt?: PrefBoundAt;
|
|
377
423
|
step?: number;
|
|
378
424
|
control?: PrefNumberControl;
|
|
379
425
|
/** How the value shows, speaks and reads back when typed — `compact()`
|
|
@@ -385,6 +431,20 @@ interface PrefNumber extends PrefBase<'number', number> {
|
|
|
385
431
|
/** The word infinity shows as — `'never'`, `'uncapped'`. Default `∞`. */
|
|
386
432
|
infinity?: InfinityText;
|
|
387
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* A numeric pref, optionally bounded and stepped, and optionally stored in a
|
|
436
|
+
* different unit from the one shown.
|
|
437
|
+
*
|
|
438
|
+
* `clearable` says the field may hold no number, which a person sets by
|
|
439
|
+
* emptying it: the value is then `undefined`, which the owner reads as unset,
|
|
440
|
+
* and its default may be too.
|
|
441
|
+
*/
|
|
442
|
+
type PrefNumber = PrefNumberBase & ({
|
|
443
|
+
clearable?: false;
|
|
444
|
+
default: number;
|
|
445
|
+
} | {
|
|
446
|
+
clearable: true;
|
|
447
|
+
});
|
|
388
448
|
/**
|
|
389
449
|
* Stored-value bridge for a boolean leaf whose field is not a boolean — the
|
|
390
450
|
* flag counterpart of {@link PrefEnumEncoding}. `TextStyle.fontStyle` is
|
|
@@ -397,12 +457,12 @@ interface PrefBooleanEncoding {
|
|
|
397
457
|
write: (on: boolean, siblings: Record<string, unknown> | undefined) => unknown;
|
|
398
458
|
}
|
|
399
459
|
/** An on/off pref. */
|
|
400
|
-
interface PrefBoolean extends
|
|
460
|
+
interface PrefBoolean extends PrefValueBase<'boolean', boolean> {
|
|
401
461
|
control?: PrefBooleanControl;
|
|
402
462
|
encoding?: PrefBooleanEncoding;
|
|
403
463
|
}
|
|
404
464
|
/** A free-text pref. */
|
|
405
|
-
interface PrefString extends
|
|
465
|
+
interface PrefString extends PrefValueBase<'string', string> {
|
|
406
466
|
control?: PrefStringControl;
|
|
407
467
|
}
|
|
408
468
|
/**
|
|
@@ -427,13 +487,11 @@ interface PrefEnumEncoding<T extends string = string> {
|
|
|
427
487
|
write: (option: T, siblings: Record<string, unknown> | undefined) => unknown;
|
|
428
488
|
}
|
|
429
489
|
/** What every enum leaf carries; {@link PrefEnum} adds `clearable`. */
|
|
430
|
-
interface PrefEnumBase<T extends string = string> extends
|
|
490
|
+
interface PrefEnumBase<T extends string = string> extends PrefValueBase<'enum', T | undefined> {
|
|
431
491
|
/** `short` holds shorter forms of `label`, longest first, for a segmented
|
|
432
492
|
* control too narrow for the full one — down to a capital or two. `icon`
|
|
433
|
-
* names a glyph in
|
|
434
|
-
* `
|
|
435
|
-
* a plain string because this package ships no icon set and cannot
|
|
436
|
-
* depend on one. The full `label` stays the accessible name, so neither the abbreviation nor the glyph becomes the only thing naming
|
|
493
|
+
* names a glyph, drawn in place of any text form where it resolves. A name
|
|
494
|
+
* from `@weasel-js/icons`; this package draws nothing. The full `label` stays the accessible name, so neither the abbreviation nor the glyph becomes the only thing naming
|
|
437
495
|
* the option.
|
|
438
496
|
*
|
|
439
497
|
* `disabled` marks an option a control reports but cannot author — the
|
|
@@ -444,7 +502,7 @@ interface PrefEnumBase<T extends string = string> extends PrefBase<'enum', T | u
|
|
|
444
502
|
value: T;
|
|
445
503
|
label: string;
|
|
446
504
|
short?: readonly string[];
|
|
447
|
-
icon?:
|
|
505
|
+
icon?: IconRef;
|
|
448
506
|
disabled?: boolean;
|
|
449
507
|
}[];
|
|
450
508
|
control?: PrefEnumControl;
|
|
@@ -468,7 +526,7 @@ type PrefEnum<T extends string = string> = PrefEnumBase<T> & ({
|
|
|
468
526
|
});
|
|
469
527
|
/** A single color, stored as a hex string. For a value that may also be a
|
|
470
528
|
* gradient or a pattern, use {@link PrefPaint} instead. */
|
|
471
|
-
interface PrefColor extends
|
|
529
|
+
interface PrefColor extends PrefValueBase<'color', string> {
|
|
472
530
|
/** Value is `#rrggbb`, or `#rrggbbaa` when `alpha` is set (UIs then
|
|
473
531
|
* offer an opacity control). */
|
|
474
532
|
alpha?: boolean;
|
|
@@ -478,7 +536,7 @@ interface PrefColor extends PrefBase<'color', string> {
|
|
|
478
536
|
* UIs dispatch it to an app-supplied renderer. Deliberately NOT
|
|
479
537
|
* index-signatured so concrete app interfaces stay assignable.
|
|
480
538
|
*/
|
|
481
|
-
type PrefCustom =
|
|
539
|
+
type PrefCustom = PrefValueBase<string, unknown>;
|
|
482
540
|
/**
|
|
483
541
|
* A whole `Paint`, not a color inside one. Use it wherever the value is
|
|
484
542
|
* the tagged paint union — a solid color, a pattern, a gradient — rather
|
|
@@ -490,7 +548,7 @@ type PrefCustom = PrefBase<string, unknown>;
|
|
|
490
548
|
* `'color' in paint` checks then paint flat solid. The union has to be
|
|
491
549
|
* edited as a union.
|
|
492
550
|
*/
|
|
493
|
-
interface PrefPaint extends
|
|
551
|
+
interface PrefPaint extends PrefValueBase<'paint', unknown> {
|
|
494
552
|
/** Offer an opacity control alongside the color. */
|
|
495
553
|
alpha?: boolean;
|
|
496
554
|
}
|
|
@@ -506,7 +564,7 @@ interface PrefPaint extends PrefBase<'paint', unknown> {
|
|
|
506
564
|
* edits that union. A child may also be a {@link PrefSection}, which
|
|
507
565
|
* organizes the fields under a heading without contributing to the path.
|
|
508
566
|
*/
|
|
509
|
-
interface PrefObject extends
|
|
567
|
+
interface PrefObject extends PrefValueBase<'object', unknown> {
|
|
510
568
|
children: Record<string, PrefLeaf | PrefSection>;
|
|
511
569
|
/**
|
|
512
570
|
* Lift a non-object value into the object form, for a consumer field that
|
|
@@ -521,13 +579,13 @@ interface PrefObject extends PrefBase<'object', unknown> {
|
|
|
521
579
|
* value is read and written at (`'camera.type'`) — the currency fields refer
|
|
522
580
|
* to each other in. A surface offers the fields it draws as the choices.
|
|
523
581
|
*/
|
|
524
|
-
interface PrefField extends
|
|
582
|
+
interface PrefField extends PrefValueBase<'field', string> {
|
|
525
583
|
/** Only fields of these kinds may be named. Default: any leaf. */
|
|
526
584
|
kinds?: readonly string[];
|
|
527
585
|
}
|
|
528
586
|
/** One built-in pref leaf. `PrefLeaf` widens this to include
|
|
529
587
|
* app-defined kinds. */
|
|
530
|
-
type BuiltinPref = PrefNumber | PrefBoolean | PrefString | PrefEnum | PrefColor | PrefPaint | PrefObject | PrefList | PrefMap | PrefUnion | PrefField | PrefAction | PrefAlias | PrefLabel | PrefSeparator;
|
|
588
|
+
type BuiltinPref = PrefNumber | PrefBoolean | PrefString | PrefEnum | PrefColor | PrefPaint | PrefObject | PrefList | PrefMap | PrefUnion | PrefField | PrefAction | PrefActions | PrefAlias | PrefLabel | PrefSeparator;
|
|
531
589
|
/**
|
|
532
590
|
* The built-in kinds, as a table. A kind added to {@link PrefKind} is a
|
|
533
591
|
* compile error here, and from here it is one in every renderer's `never`
|
|
@@ -559,8 +617,11 @@ type PrefLeaf = BuiltinPref | PrefCustom;
|
|
|
559
617
|
* `fragment` draws nothing of its own, so its rows sit among its neighbors'
|
|
560
618
|
* as though they were written there. A fragment exists to hold things
|
|
561
619
|
* together: one key for their values to nest under, one node to move.
|
|
620
|
+
* `bar` puts its prefs on one line in their bar forms. `menu` is drawn as
|
|
621
|
+
* a menu wherever a menu fits: on a bar, a button opening its contents as a
|
|
622
|
+
* menu; in a menu, a submenu; in a panel, a titled box as `panel` is.
|
|
562
623
|
*/
|
|
563
|
-
type PrefGroupAs = 'page' | 'tab' | 'panel' | 'section' | 'fragment' | 'bar';
|
|
624
|
+
type PrefGroupAs = 'page' | 'tab' | 'panel' | 'section' | 'fragment' | 'bar' | 'menu';
|
|
564
625
|
/**
|
|
565
626
|
* What a group or a section drawn `as: 'bar'` does with cells its line has no
|
|
566
627
|
* room for: `scroll` keeps them all on it, and `menu` opens the ones past its
|
|
@@ -568,6 +629,8 @@ type PrefGroupAs = 'page' | 'tab' | 'panel' | 'section' | 'fragment' | 'bar';
|
|
|
568
629
|
* has along the line, which is why it is asked for and not the default.
|
|
569
630
|
*/
|
|
570
631
|
type PrefBarOverflow = 'scroll' | 'menu';
|
|
632
|
+
/** What a bar's line starts with, ahead of its cells: `label` puts the bar's name there, and `icon` its `icon`. */
|
|
633
|
+
type PrefBarLead = 'label' | 'icon';
|
|
571
634
|
/** How a {@link PrefSection} is drawn. */
|
|
572
635
|
type PrefSectionAs = Exclude<PrefGroupAs, 'page'>;
|
|
573
636
|
/**
|
|
@@ -584,6 +647,9 @@ interface PrefGroup {
|
|
|
584
647
|
* reads as nothing without it). */
|
|
585
648
|
name: string;
|
|
586
649
|
description?: string;
|
|
650
|
+
/** Tags every leaf under the group carries besides its own. A settings
|
|
651
|
+
* search matching one keeps the whole group, as matching its name does. */
|
|
652
|
+
tags?: readonly string[];
|
|
587
653
|
/** How the group is drawn. Unset, its depth decides: a top-level group is a
|
|
588
654
|
* `page`, and one inside another is a `section`. */
|
|
589
655
|
as?: PrefGroupAs;
|
|
@@ -591,6 +657,14 @@ interface PrefGroup {
|
|
|
591
657
|
* Unset: `scroll`. A surface that takes drops keeps every cell on the line
|
|
592
658
|
* whatever this says, so each is there to drop beside. */
|
|
593
659
|
overflow?: PrefBarOverflow;
|
|
660
|
+
/** Drawn `as: 'bar'`: what its line starts with. Unset: its first cell. */
|
|
661
|
+
lead?: PrefBarLead;
|
|
662
|
+
/** Glyph naming the group, as a leaf's `icon` names the leaf. A bar drawn
|
|
663
|
+
* with `lead: 'icon'` starts its line with it; the button a bar opens the
|
|
664
|
+
* group from and its submenu row in a menu carry it beside its name. */
|
|
665
|
+
icon?: IconRef;
|
|
666
|
+
/** The letter that picks this in a menu, and with the menu bar's chord opens a top-level menu. One character; supported, never required. */
|
|
667
|
+
access?: string;
|
|
594
668
|
/** Drawn, with everything under it, only while this holds. */
|
|
595
669
|
showIf?: PrefCondition;
|
|
596
670
|
/** Everything under it is disabled while this does not hold. */
|
|
@@ -609,6 +683,8 @@ interface PrefSection {
|
|
|
609
683
|
* {@link PrefGroup}. */
|
|
610
684
|
name: string;
|
|
611
685
|
description?: string;
|
|
686
|
+
/** As a {@link PrefGroup}'s. */
|
|
687
|
+
tags?: readonly string[];
|
|
612
688
|
/** How the section is drawn, as a {@link PrefGroup}'s `as` — without
|
|
613
689
|
* `page`, since nothing that draws sections has a rail. Unset: a heading
|
|
614
690
|
* over its rows. */
|
|
@@ -616,211 +692,21 @@ interface PrefSection {
|
|
|
616
692
|
/** As a {@link PrefGroup}'s. */
|
|
617
693
|
overflow?: PrefBarOverflow;
|
|
618
694
|
/** As a {@link PrefGroup}'s. */
|
|
695
|
+
lead?: PrefBarLead;
|
|
696
|
+
/** As a {@link PrefGroup}'s. */
|
|
697
|
+
icon?: IconRef;
|
|
698
|
+
/** As a {@link PrefGroup}'s. */
|
|
699
|
+
access?: string;
|
|
700
|
+
/** As a {@link PrefGroup}'s. */
|
|
619
701
|
showIf?: PrefCondition;
|
|
620
702
|
/** As a {@link PrefGroup}'s. */
|
|
621
703
|
enableIf?: PrefCondition;
|
|
622
704
|
members: Record<string, PrefLeaf | PrefSection>;
|
|
623
705
|
}
|
|
706
|
+
/** Whether a panel draws a group or a section drawn `as` this in a bordered, titled box: a `panel`, and a `menu`,
|
|
707
|
+
* which a panel has no menu to open as. */
|
|
708
|
+
declare function prefAsBox(as: PrefGroupAs | undefined): boolean;
|
|
624
709
|
/** Whether a top-level group gets a page of its own, and not a place on the page of the root's own leaves. */
|
|
625
710
|
declare function prefGroupIsPage(group: PrefGroup): boolean;
|
|
626
711
|
|
|
627
|
-
|
|
628
|
-
* Folds a split value's alternatives into the one value read. `members` holds
|
|
629
|
-
* two or more, each weighing more than nothing, and their weights need not
|
|
630
|
-
* sum to 1.
|
|
631
|
-
*/
|
|
632
|
-
type PrefBlend = (members: readonly PrefWeighted[], leaf: PrefLeaf) => unknown;
|
|
633
|
-
/** The blends of the built-in kinds that have one. Every other kind takes its heaviest member. */
|
|
634
|
-
declare const PREF_BLENDS: Readonly<Record<string, PrefBlend>>;
|
|
635
|
-
|
|
636
|
-
type Join<A extends string, B extends string> = A extends '' ? B : `${A}.${B}`;
|
|
637
|
-
/** Every value's dotted path in a `PrefGroup` schema, where a group's key is a
|
|
638
|
-
* segment; an `object` leaf is one path, its fields are not, and an `action`,
|
|
639
|
-
* `alias`, `label`, or `separator` leaf, holding no value, has none. A `PrefSection`
|
|
640
|
-
* has no such paths: each of its leaves is addressed by its own key. */
|
|
641
|
-
type PrefPath<G, Prefix extends string = ''> = G extends {
|
|
642
|
-
children: infer C;
|
|
643
|
-
} ? string extends keyof C ? Join<Prefix, string> : {
|
|
644
|
-
[K in keyof C & string]: C[K] extends {
|
|
645
|
-
kind: string;
|
|
646
|
-
} ? C[K] extends {
|
|
647
|
-
kind: 'action' | 'alias' | 'label' | 'separator';
|
|
648
|
-
} ? never : Join<Prefix, K> : C[K] extends {
|
|
649
|
-
children: Record<string, unknown>;
|
|
650
|
-
} ? PrefPath<C[K], Join<Prefix, K>> : never;
|
|
651
|
-
}[keyof C & string] : never;
|
|
652
|
-
/** The leaf at `P`. `unknown` under a group whose keys are not literal, as a
|
|
653
|
-
* schema built at run time has them: nothing says which leaf is there, so
|
|
654
|
-
* its value reads as `unknown`. */
|
|
655
|
-
type PrefAtPath<G, P extends string> = G extends {
|
|
656
|
-
children: infer C;
|
|
657
|
-
} ? string extends keyof C ? unknown : P extends `${infer H}.${infer Rest}` ? H extends keyof C ? C[H] extends {
|
|
658
|
-
kind: string;
|
|
659
|
-
} ? never : PrefAtPath<C[H], Rest> : never : P extends keyof C ? C[P] extends {
|
|
660
|
-
kind: string;
|
|
661
|
-
} ? C[P] : never : never : never;
|
|
662
|
-
type AllOf<U> = (U extends unknown ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
663
|
-
/** The fields an `object` leaf's `children` describe, sections folded in. Each is optional: an object may omit any. */
|
|
664
|
-
type PrefFieldsOf<C> = {
|
|
665
|
-
[K in keyof C as C[K] extends {
|
|
666
|
-
kind: string;
|
|
667
|
-
} ? K : never]?: PrefValueOf<C[K]>;
|
|
668
|
-
} & AllOf<{
|
|
669
|
-
[K in keyof C]: C[K] extends {
|
|
670
|
-
members: infer M;
|
|
671
|
-
} ? PrefFieldsOf<M> : never;
|
|
672
|
-
}[keyof C]>;
|
|
673
|
-
/** What a leaf holds: its kind's value type for a built-in kind, the type of
|
|
674
|
-
* its `default` for an app-defined one. A list holds an array of what its
|
|
675
|
-
* `item` holds, a map a record of it, and a union one variant's fields
|
|
676
|
-
* under that variant's tag — where the schema keeps `tag` a literal
|
|
677
|
-
* (`tag: 'type' as const`); one widened to `string` is typed by its default. */
|
|
678
|
-
type PrefValueOf<L> = L extends {
|
|
679
|
-
kind: 'number';
|
|
680
|
-
} ? number : L extends {
|
|
681
|
-
kind: 'boolean';
|
|
682
|
-
} ? boolean : L extends {
|
|
683
|
-
kind: 'string' | 'color' | 'field';
|
|
684
|
-
} ? string : L extends {
|
|
685
|
-
kind: 'paint';
|
|
686
|
-
} ? unknown : L extends {
|
|
687
|
-
kind: 'enum';
|
|
688
|
-
options: readonly {
|
|
689
|
-
value: infer T;
|
|
690
|
-
}[];
|
|
691
|
-
} ? L extends {
|
|
692
|
-
clearable: true;
|
|
693
|
-
} ? T | undefined : T : L extends {
|
|
694
|
-
kind: 'list';
|
|
695
|
-
item: infer I;
|
|
696
|
-
} ? PrefValueOf<I>[] : L extends {
|
|
697
|
-
kind: 'map';
|
|
698
|
-
item: infer I;
|
|
699
|
-
} ? Record<string, PrefValueOf<I>> : L extends {
|
|
700
|
-
kind: 'union';
|
|
701
|
-
tag: infer T extends string;
|
|
702
|
-
variants: infer V;
|
|
703
|
-
default: infer D;
|
|
704
|
-
} ? string extends keyof V | T ? D : {
|
|
705
|
-
[K in keyof V & string]: {
|
|
706
|
-
[P in T]: K;
|
|
707
|
-
} & (V[K] extends {
|
|
708
|
-
children: infer C;
|
|
709
|
-
} ? PrefFieldsOf<C> : unknown);
|
|
710
|
-
}[keyof V & string] : L extends {
|
|
711
|
-
default: infer D;
|
|
712
|
-
} ? D : unknown;
|
|
713
|
-
/** What the leaf at `P` holds. */
|
|
714
|
-
type PrefValueAt<G, P extends string> = PrefValueOf<PrefAtPath<G, P>>;
|
|
715
|
-
|
|
716
|
-
/** Takes stored values from one version to the next: rename, transform or
|
|
717
|
-
* delete entries in `records`, keyed by leaf path. It sees the values, not
|
|
718
|
-
* the stamps they are stored under, and only those at its own version. */
|
|
719
|
-
type PrefsMigration = (records: Map<string, unknown>) => void;
|
|
720
|
-
|
|
721
|
-
/** Decides what a stored value reads as for one kind of leaf: the value to
|
|
722
|
-
* read, or `undefined` for "invalid, read the default". */
|
|
723
|
-
type PrefValidator = (stored: unknown, leaf: PrefLeaf) => unknown;
|
|
724
|
-
/** What `stored` reads as for `leaf`. Never writes anything back: a schema
|
|
725
|
-
* rolled back finds the original still in storage. */
|
|
726
|
-
declare function repairPrefValue(leaf: PrefLeaf, stored: unknown, validators?: Readonly<Record<string, PrefValidator>>): unknown;
|
|
727
|
-
|
|
728
|
-
/** One leaf changing, as a store subscriber hears it: the value readers now
|
|
729
|
-
* see, and whether this store or another writer made the change. */
|
|
730
|
-
interface PrefChange {
|
|
731
|
-
path: string;
|
|
732
|
-
value: unknown;
|
|
733
|
-
origin: 'local' | 'remote';
|
|
734
|
-
}
|
|
735
|
-
/** Values for one schema, held in memory and persisted behind. */
|
|
736
|
-
interface PrefsStore<S extends PrefGroup> {
|
|
737
|
-
readonly schema: S;
|
|
738
|
-
/**
|
|
739
|
-
* The leaf's value, repaired against the schema; its default when unset. A
|
|
740
|
-
* split value is folded: under the selectors' own values it is the member
|
|
741
|
-
* they name, and under `weights` it is the blend its kind makes of the
|
|
742
|
-
* members that weigh something. A selector `weights` leaves out keeps its
|
|
743
|
-
* own value.
|
|
744
|
-
*/
|
|
745
|
-
get<P extends PrefPath<S>>(path: P, read?: {
|
|
746
|
-
weights?: PrefWeights;
|
|
747
|
-
}): PrefValueAt<S, P>;
|
|
748
|
-
/** On a split leaf, writes the member the selectors' own values name, or
|
|
749
|
-
* with `at` the one named with each selector there set to the option given.
|
|
750
|
-
* A {@link PrefLocus} given as the value replaces the whole of what is held. */
|
|
751
|
-
set<P extends PrefPath<S>>(path: P, value: PrefValueAt<S, P> | PrefLocus, write?: {
|
|
752
|
-
at?: PrefSelection;
|
|
753
|
-
}): void;
|
|
754
|
-
/** Hold the leaf's value once per option of the selector at `by`, one of
|
|
755
|
-
* the leaf's `splitBy`, each option starting as the value it had. */
|
|
756
|
-
split(path: PrefPath<S>, by: string): void;
|
|
757
|
-
/** Stop splitting the leaf's value by the selector at `by`, keeping the
|
|
758
|
-
* member that selector's own value names. */
|
|
759
|
-
join(path: PrefPath<S>, by: string): void;
|
|
760
|
-
/** What the leaf holds where its value is split, each member repaired. */
|
|
761
|
-
locus(path: PrefPath<S>): PrefLocus | undefined;
|
|
762
|
-
/** What every split leaf holds, by its path. The same map until something changes. */
|
|
763
|
-
loci(): ReadonlyMap<string, PrefLocus>;
|
|
764
|
-
/** Unset every leaf at or under `path`; with no path, all. */
|
|
765
|
-
reset(path?: string): void;
|
|
766
|
-
/** Whether the leaf has a value of its own rather than following its default. */
|
|
767
|
-
isSet(path: PrefPath<S>): boolean;
|
|
768
|
-
/** Every leaf's value as a nested tree. The same object until something
|
|
769
|
-
* changes. With `at`, the tree as it would read with each selector named
|
|
770
|
-
* there set to the option given, built for the call. */
|
|
771
|
-
values(read?: {
|
|
772
|
-
at?: PrefSelection;
|
|
773
|
-
}): Record<string, unknown>;
|
|
774
|
-
/** The leaves following their default. The same set until something changes. */
|
|
775
|
-
unset(): ReadonlySet<string>;
|
|
776
|
-
/** Every stored record as a nested tree, unrepaired, including records no
|
|
777
|
-
* leaf describes. The same object until something changes. */
|
|
778
|
-
stored(): Record<string, unknown>;
|
|
779
|
-
/** `changes` is empty when only records no leaf describes changed. A
|
|
780
|
-
* selector changing is a change to every leaf split by it. */
|
|
781
|
-
subscribe(listener: (changes: PrefChange[]) => void): () => void;
|
|
782
|
-
/** False while the store cannot persist: storage has not been read yet, or
|
|
783
|
-
* was written by a newer schema. Changes still apply for this session, and
|
|
784
|
-
* ones made before a late read lands are persisted when it does. False for
|
|
785
|
-
* good once the store is closed. */
|
|
786
|
-
readonly writable: boolean;
|
|
787
|
-
/** True once `close` was called. A write after that changes what this store
|
|
788
|
-
* reads and reaches neither storage nor its subscribers, and the first one
|
|
789
|
-
* warns. */
|
|
790
|
-
readonly closed: boolean;
|
|
791
|
-
/** Try again now to read storage that could not be read at open, ahead of
|
|
792
|
-
* the store's own retries. Resolves whether storage has been read. */
|
|
793
|
-
read(): Promise<boolean>;
|
|
794
|
-
/** Resolves once storage has been read: at once for a store that opened
|
|
795
|
-
* with its values, and when a later read lands for one that could not. */
|
|
796
|
-
whenRead(): Promise<void>;
|
|
797
|
-
/** Resolves true when every queued write reached storage. */
|
|
798
|
-
flush(): Promise<boolean>;
|
|
799
|
-
close(): Promise<void>;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
/** Options for `openPrefs` and `openPrefsSync`. */
|
|
803
|
-
interface PrefsOptions {
|
|
804
|
-
storage: StorageAdapter;
|
|
805
|
-
/** Prepended to every record's key: `'myapp.prefs.'`. */
|
|
806
|
-
prefix: string;
|
|
807
|
-
/** `migrations[i]` takes stored records from version `i` to `i + 1`. The
|
|
808
|
-
* current version is `migrations.length`. */
|
|
809
|
-
migrations?: readonly PrefsMigration[];
|
|
810
|
-
/** Validators for app-defined kinds, keyed by `kind`. One given for a
|
|
811
|
-
* built-in kind replaces that kind's own rule. */
|
|
812
|
-
validators?: Readonly<Record<string, PrefValidator>>;
|
|
813
|
-
/** How a split value's alternatives fold into one for app-defined kinds,
|
|
814
|
-
* keyed by `kind`. One given for a built-in kind replaces that kind's
|
|
815
|
-
* own. A kind with none takes its heaviest alternative. */
|
|
816
|
-
blends?: Readonly<Record<string, PrefBlend>>;
|
|
817
|
-
}
|
|
818
|
-
/** Load every stored value for `schema`, migrate it, and return the store. */
|
|
819
|
-
declare function openPrefs<S extends PrefGroup>(schema: S, options: PrefsOptions): Promise<PrefsStore<S>>;
|
|
820
|
-
/** `openPrefs` for an adapter that reads synchronously: the store is ready
|
|
821
|
-
* on return, so values can be read before anything renders. */
|
|
822
|
-
declare function openPrefsSync<S extends PrefGroup>(schema: S, options: PrefsOptions & {
|
|
823
|
-
storage: SyncStorageAdapter;
|
|
824
|
-
}): PrefsStore<S>;
|
|
825
|
-
|
|
826
|
-
export { type PrefWeighted as $, type PrefBooleanEncoding as A, type BuiltinPref as B, type PrefChange as C, type PrefConditionValue as D, type PrefCustom as E, type PrefEnum as F, type PrefEnumControl as G, type PrefEnumEncoding as H, type PrefField as I, type PrefFunctionUnit as J, type PrefGroupAs as K, type PrefLabel as L, type PrefLinearUnit as M, type PrefNumberControl as N, type PrefNumberUnit as O, type PrefLeaf as P, type PrefPaint as Q, type PrefPair as R, type PrefPath as S, type PrefSectionAs as T, type PrefSeparator as U, type PrefStringControl as V, type PrefTest as W, type PrefUnion as X, type PrefValidator as Y, type PrefValueAt as Z, type PrefValueOf as _, type PrefGroup as a, type PrefWeights as a0, type PrefsMigration as a1, type PrefsOptions as a2, type PrefsStore as a3, type ResolvedPrefUnit as a4, isBuiltinPref as a5, isPrefCondition as a6, isPrefLinearUnit as a7, isPrefLocus as a8, mapPrefConditionPaths as a9, openPrefs as aa, openPrefsSync as ab, pairRowsOf as ac, prefAliasName as ad, prefAliasTarget as ae, prefAliasedLeaf as af, prefConditionHolds as ag, prefConditionPaths as ah, prefConditionReadsItem as ai, prefGroupIsPage as aj, prefIsEnabled as ak, prefIsShown as al, memberAt as am, locusSelectors as an, prefUnit as ao, prefVariantDefault as ap, prefVariantOf as aq, repairPrefValue as ar, resolvePrefUnit as as, type PrefSection as b, type PrefNumber as c, type PrefList as d, type PrefMap as e, type PrefCondition as f, type PrefConditionReader as g, type PrefBoolean as h, type PrefString as i, type PrefColor as j, type PrefEnumBase as k, type PrefSelection as l, type PrefLocus as m, type PrefAlias as n, type PrefObject as o, type PrefKind as p, PREF_BLENDS as q, PREF_KINDS as r, type PrefAction as s, type PrefActionContext as t, type PrefActionControl as u, type PrefAtPath as v, type PrefBarOverflow as w, type PrefBase as x, type PrefBlend as y, type PrefBooleanControl as z };
|
|
712
|
+
export { type ResolvedPrefUnit as $, type PrefBoundAt as A, type BuiltinPref as B, type PrefBoundReader as C, type PrefConditionValue as D, type PrefCustom as E, type PrefEnum as F, type PrefEnumControl as G, type PrefEnumEncoding as H, type PrefField as I, type PrefFunctionUnit as J, type PrefGroupAs as K, type PrefLinearUnit as L, type PrefLocus as M, type PrefNumberBase as N, type PrefNumberControl as O, type PrefLeaf as P, type PrefNumberUnit as Q, type PrefPaint as R, type PrefPair as S, type PrefSectionAs as T, type PrefSelection as U, type PrefStringControl as V, type PrefTest as W, type PrefUnion as X, type PrefValueBase as Y, type PrefWeighted as Z, type PrefWeights as _, type PrefGroup as a, isBuiltinPref as a0, isPrefCondition as a1, isPrefLinearUnit as a2, isPrefLocus as a3, mapPrefConditionPaths as a4, pairRowsOf as a5, prefAliasName as a6, prefAliasTarget as a7, prefAliasedLeaf as a8, prefAsBox as a9, prefClampNumber as aa, prefConditionHolds as ab, prefConditionPaths as ac, prefConditionReadsItem as ad, prefGroupIsPage as ae, prefIsEnabled as af, prefIsShown as ag, memberAt as ah, locusSelectors as ai, prefNumberAt as aj, prefUnit as ak, prefUnitAccepts as al, prefVariantDefault as am, prefVariantOf as an, resolvePrefUnit as ao, type PrefSection as b, type PrefNumber as c, type PrefList as d, type PrefMap as e, type PrefCondition as f, type PrefConditionReader as g, type PrefBoolean as h, type PrefString as i, type PrefColor as j, type PrefEnumBase as k, type PrefAction as l, type PrefActions as m, type PrefLabel as n, type PrefSeparator as o, type PrefAlias as p, type PrefObject as q, type PrefKind as r, PREF_KINDS as s, type PrefActionContext as t, type PrefActionControl as u, type PrefBarLead as v, type PrefBarOverflow as w, type PrefBase as x, type PrefBooleanControl as y, type PrefBooleanEncoding as z };
|