@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 CHANGED
@@ -42,6 +42,27 @@ It takes an adapter that reads synchronously, and components naming the same
42
42
  `storage` and `prefix` with different schemas each get a store over the same
43
43
  records.
44
44
 
45
+ ## Tags
46
+
47
+ A leaf, a group, and a section can each carry `tags`: words a settings search
48
+ also finds it by, and that gather it with others. A leaf carries its own and
49
+ every group's above it, so tagging a group tags all it holds:
50
+
51
+ ```ts
52
+ canvas: { name: 'Canvas', tags: ['workspace'], children: {
53
+ grid: { kind: 'boolean', name: 'Show grid', description: '', default: true, tags: ['guides'] },
54
+ } },
55
+
56
+ prefLeavesTagged(SCHEMA, 'guides'); // Map { 'canvas.grid' => … }
57
+ prefLeafTags(SCHEMA, 'canvas.grid'); // ['workspace', 'guides']
58
+ filterPrefSubtree(SCHEMA, 'guide'); // keeps canvas.grid, matched by its tag
59
+ ```
60
+
61
+ A search matches a tag as it matches a name, and a group a tag matches keeps
62
+ all its leaves, as one its name matches does. An alias carries its target's
63
+ tags and its own. `tags` is unrelated to a `union` leaf's `tag`, the field its
64
+ value's variant is read from.
65
+
45
66
  ## Ranges
46
67
 
47
68
  A number leaf's range is one scale: the low end is the least of what its label
@@ -52,6 +73,15 @@ a 0–100% limit is off at 100, and a scale with no such end takes `endless`,
52
73
  which adds a stop one step past the range that stores `Infinity` and reads the
53
74
  leaf's `infinity` word.
54
75
 
76
+ A bound that depends on where the value is held takes `minAt` or `maxAt`: a
77
+ function handed a reader of the values beside it, by the paths a condition
78
+ there would name, returning the bound or `undefined`. It is taken with `min`
79
+ or `max`, the tighter winning, and `prefNumberAt(leaf, read)` folds it in for
80
+ one holder. A box's width that may not go under its node's own minimum reads
81
+ `data.minSize` this way: `SelectionPanel` resolves it against each node and
82
+ holds each write to that node's bound, and `PrefsForm` and labkit's
83
+ `ControlPanel` resolve it against their values.
84
+
55
85
  ## Split values
56
86
 
57
87
  A leaf that lists `splitBy` may hold its value once per option of another
@@ -135,3 +165,24 @@ come later. A number is written in its display unit where the unit's suffix is
135
165
  a CSS unit, a boolean as `1` or `0`, an enum's option as an identifier, and a
136
166
  string quoted; a leaf of any other kind is left out unless the `value` option
137
167
  writes it. `root`, `property`, and `attribute` rename what it writes.
168
+
169
+ `prefsDefaultsSource(schema)` stands in for a store at its defaults, so
170
+ `prefsCss(prefsDefaultsSource(schema))` is a schema's stylesheet with no store.
171
+ The Vite plugin in `@weasel-js/prefs/vite` serves that sheet for every schema
172
+ you name, by module and export, and rewrites it when a schema changes:
173
+
174
+ ```ts
175
+ // vite.config.ts
176
+ import { weaselPrefsCss } from '@weasel-js/prefs/vite';
177
+ export default { plugins: [weaselPrefsCss({ schemas: { './src/prefs.ts': 'SCHEMA' } })] };
178
+
179
+ // main.ts
180
+ import 'virtual:weasel-prefs.css';
181
+ ```
182
+
183
+ For the kit's own settings, `<KitSettingsFromPrefs store at="kit">` in
184
+ `@weasel-js/prefs/react` hands the store's values under `kit` to
185
+ `KitSettingsProvider`, so `useKitSetting('tree.typeaheadMs')` reads the user's
186
+ value. With `css`, it also writes that subtree as `--wzl-kit-*` properties into
187
+ the document or shadow root it renders in, and keeps them current as the store
188
+ changes; `kitSettingsCssOptions(at)` is the naming it uses.