@tradalab/lyra 3.3.0 → 3.5.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 +32 -0
- package/dist/blocks/index.d.ts +85 -4
- package/dist/blocks/index.js +157 -27
- package/dist/blocks/index.js.map +1 -1
- package/dist/{chunk-DUWK53B5.js → chunk-EJP7F42V.js} +41 -4
- package/dist/chunk-EJP7F42V.js.map +1 -0
- package/dist/ui/index.js +4 -41
- package/dist/ui/index.js.map +1 -1
- package/package.json +1 -1
- package/styles/globals.css +585 -0
- package/dist/chunk-DUWK53B5.js.map +0 -1
package/README.md
CHANGED
|
@@ -27,6 +27,7 @@ The stylesheet pulls in Tailwind v4, so your app needs `@tailwindcss/postcss`.
|
|
|
27
27
|
| `@tradalab/lyra/utils` | `cn` | server-safe |
|
|
28
28
|
| `@tradalab/lyra/hooks` | `useMobile` | client |
|
|
29
29
|
| `@tradalab/lyra/ui` | 60 shadcn primitives + `AccountMenu`, `ActionButton`, `Container`, `EmptyState`, `StatusBadge` | client |
|
|
30
|
+
| `@tradalab/lyra/blocks` | `Form`/`FormField` + RHF glue, `Panel`, `Confirm`/`useConfirm`, `Tree`, `TzPicker`, `OptionPicker`, `McpSettings`, `LlmSettings`, `PlatePicker`, `usePlate`, `useCompact`, `PreferenceScript` | client |
|
|
30
31
|
| `@tradalab/lyra/shell` | `AppShell`, `PageShell`, `PageHeader`, `NavItem`, `NavGroup`, `Breadcrumbs`, `useActiveRoute` | client |
|
|
31
32
|
| `@tradalab/lyra/styles.css` | Tailwind v4 base + `radix-lyra` tokens (light/dark) | CSS |
|
|
32
33
|
|
|
@@ -61,6 +62,37 @@ Infinity`). Position belongs to the viewport this package styles, so sonner's
|
|
|
61
62
|
`position` and `richColors` props have no equivalent. Mount `<Toaster/>` once —
|
|
62
63
|
apps on `@tradalab/nekit` already get it from `NekitProvider`.
|
|
63
64
|
|
|
65
|
+
## Plate and density
|
|
66
|
+
|
|
67
|
+
`3.4.0` added a palette the reader picks. The colours live in `styles.css` behind
|
|
68
|
+
`[data-plate="<name>"]`, so an app only wires the choice:
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import { PlatePicker, PreferenceScript, useCompact, usePlate } from "@tradalab/lyra/blocks"
|
|
72
|
+
|
|
73
|
+
// In the root layout, as early in the tree as possible.
|
|
74
|
+
<PreferenceScript />
|
|
75
|
+
|
|
76
|
+
// On a settings screen.
|
|
77
|
+
const [plate, setPlate] = usePlate()
|
|
78
|
+
<PlatePicker value={plate} onChange={setPlate} label="Accent colour" resetLabel="Default" />
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`usePlate` and `useCompact` remember the choice per DEVICE, in `localStorage`
|
|
82
|
+
under `lyra.plate` and `lyra.compact`, which is the same granularity as the
|
|
83
|
+
theme. Absence means the default, so turning one off removes its key rather than
|
|
84
|
+
storing "off".
|
|
85
|
+
|
|
86
|
+
Keep `suppressHydrationWarning` on `<html>`. The script writes attributes the
|
|
87
|
+
server did not render, which is the same reason `next-themes` needs it; every
|
|
88
|
+
tradalab layout and `template-web` already carry it.
|
|
89
|
+
|
|
90
|
+
Leaving out `<PreferenceScript />` is neither a compile error nor a runtime one.
|
|
91
|
+
The attributes then arrive from an effect, so the first paint is always the
|
|
92
|
+
neutral default and every reader who chose a colour watches it flip. It has to be
|
|
93
|
+
a raw inline script to beat that paint, which is why lyra renders it instead of
|
|
94
|
+
leaving it to each app.
|
|
95
|
+
|
|
64
96
|
## Develop
|
|
65
97
|
|
|
66
98
|
```bash
|
package/dist/blocks/index.d.ts
CHANGED
|
@@ -33,10 +33,17 @@ type PanelItemType = {
|
|
|
33
33
|
hasError?: boolean;
|
|
34
34
|
content: ReactNode;
|
|
35
35
|
};
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
/**
|
|
37
|
+
* No URL binding, on purpose.
|
|
38
|
+
*
|
|
39
|
+
* An `enable_url` prop used to mirror the open item into a query param, and that made this file
|
|
40
|
+
* import `next/navigation` at module scope. Since the `blocks` barrel re-exports everything, one
|
|
41
|
+
* import here made the WHOLE barrel require Next, so anything that is not itself a Next app could
|
|
42
|
+
* not import any block at all - which is how nekit broke. The prop had no caller in any of the 26
|
|
43
|
+
* consumers, and `name` existed only to build its query key, so both came out with the router.
|
|
44
|
+
*/
|
|
45
|
+
declare function Panel({ items }: {
|
|
38
46
|
items: PanelItemType[];
|
|
39
|
-
enable_url?: boolean;
|
|
40
47
|
}): React.JSX.Element | null;
|
|
41
48
|
interface PanelItemProps {
|
|
42
49
|
children: ReactNode;
|
|
@@ -373,6 +380,13 @@ interface LlmSettingsApi {
|
|
|
373
380
|
onPull?(cb: (p: LlmPullProgress) => void): () => void;
|
|
374
381
|
/** Runtimes already running on this machine, offered as providers to add. */
|
|
375
382
|
detect?(): Promise<LlmFound[]>;
|
|
383
|
+
/**
|
|
384
|
+
* An extra line under one slot, for a fact only the app knows - loom warns that N chunks were
|
|
385
|
+
* indexed by a different embedding model than the one now bound. Without a hook for it, adopting
|
|
386
|
+
* this block means silently dropping such a warning, which is what kept loom on its own 687-line
|
|
387
|
+
* copy of this screen.
|
|
388
|
+
*/
|
|
389
|
+
slotNote?(slot: string): React.ReactNode;
|
|
376
390
|
}
|
|
377
391
|
interface LlmSettingsLabels {
|
|
378
392
|
slots?: string;
|
|
@@ -414,4 +428,71 @@ declare function LlmSettings({ api, labels, className, }: {
|
|
|
414
428
|
className?: string;
|
|
415
429
|
}): React.JSX.Element;
|
|
416
430
|
|
|
417
|
-
|
|
431
|
+
/**
|
|
432
|
+
* Plates: the palette a reader picks, applied by putting `data-plate` on any element.
|
|
433
|
+
*
|
|
434
|
+
* This module holds NAMES and nothing else. The colours live once, in `styles/globals.css`, and a
|
|
435
|
+
* swatch reads them the same way the rest of the UI does - by sitting inside a `data-plate` scope
|
|
436
|
+
* and using `bg-primary`. Copying the values here would be the second table that drifts.
|
|
437
|
+
*
|
|
438
|
+
* Absent `data-plate`, `--primary` is lyra's neutral. That is the default every app ships with, so
|
|
439
|
+
* adopting plates costs an app nothing until a reader chooses.
|
|
440
|
+
*/
|
|
441
|
+
declare const PLATES: readonly ["pink", "rose", "crimson", "rust", "orange", "ochre", "amber", "honey", "gold", "olive", "lime", "green", "teal", "cyan", "azure", "blue", "indigo", "violet", "magenta"];
|
|
442
|
+
type Plate = (typeof PLATES)[number];
|
|
443
|
+
/**
|
|
444
|
+
* The plates certified to be told apart from each other, not merely from the status tokens.
|
|
445
|
+
*
|
|
446
|
+
* Only these may carry MEANING. The distinction is not decorative: a plate a reader picks for
|
|
447
|
+
* pleasure needs no relation to anyone else's, but a plate that says "which space you are typing
|
|
448
|
+
* into" stops working the moment two of them look alike - so that use gets the subset measured at
|
|
449
|
+
* dE76 >= 29.7 pairwise, in both themes.
|
|
450
|
+
*/
|
|
451
|
+
declare const BEARING_PLATES: readonly ["pink", "rust", "amber", "olive", "green", "teal", "azure", "blue", "violet"];
|
|
452
|
+
type BearingPlate = (typeof BEARING_PLATES)[number];
|
|
453
|
+
declare function isPlate(s: string): s is Plate;
|
|
454
|
+
/**
|
|
455
|
+
* The plate for an id, from the certified subset.
|
|
456
|
+
*
|
|
457
|
+
* Derived, never chosen, and that is the point when the colour is a fence rather than a preference:
|
|
458
|
+
* if two organisations could both pick blue the signal stops working for both of them. Deriving on
|
|
459
|
+
* the CLIENT is deliberate too - the alternative is every server that shows a coloured surface
|
|
460
|
+
* keeping its own copy of the name list, which is the shape chat ended up in (a Go slice, a CSS
|
|
461
|
+
* block and a TS union, with nothing holding them together).
|
|
462
|
+
*
|
|
463
|
+
* FNV-1a rather than a cryptographic hash: this picks a colour, so spreading matters and secrecy
|
|
464
|
+
* does not, and it stays synchronous - SubtleCrypto would make every call site async for nothing.
|
|
465
|
+
*/
|
|
466
|
+
declare function derivePlate(id: string): BearingPlate;
|
|
467
|
+
|
|
468
|
+
interface PlatePickerProps {
|
|
469
|
+
value: Plate | null;
|
|
470
|
+
onChange: (plate: Plate | null) => void;
|
|
471
|
+
/** Accessible name for the group, e.g. "Accent colour". */
|
|
472
|
+
label: string;
|
|
473
|
+
/** Accessible name for the neutral option, e.g. "Default". */
|
|
474
|
+
resetLabel: string;
|
|
475
|
+
/**
|
|
476
|
+
* Translated name per plate. Falls back to the plate's own key, which is English - fine for a
|
|
477
|
+
* developer tool, wrong for a product, and the reason this is a prop rather than a table in here.
|
|
478
|
+
*/
|
|
479
|
+
plateLabels?: Partial<Record<Plate, string>>;
|
|
480
|
+
className?: string;
|
|
481
|
+
}
|
|
482
|
+
declare function PlatePicker({ value, onChange, label, resetLabel, plateLabels, className }: PlatePickerProps): React.JSX.Element;
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* The plate this device is set to, and a way to change it.
|
|
486
|
+
*
|
|
487
|
+
* A stored name that is no longer a plate - a rename, a downgrade to an older lyra - reads as no
|
|
488
|
+
* plate. The alternative is an attribute no rule matches, which looks identical to the neutral
|
|
489
|
+
* default on screen while the picker shows nothing selected at all, so the reader cannot tell that
|
|
490
|
+
* their choice was dropped or get back to a known state.
|
|
491
|
+
*/
|
|
492
|
+
declare function usePlate(): [Plate | null, (plate: Plate | null) => void];
|
|
493
|
+
|
|
494
|
+
declare function useCompact(): [boolean, (compact: boolean) => void];
|
|
495
|
+
|
|
496
|
+
declare function PreferenceScript(): React.JSX.Element;
|
|
497
|
+
|
|
498
|
+
export { BEARING_PLATES, type BearingPlate, ConfirmContext, ConfirmDialog, type ConfirmFn, type ConfirmOptions, ConfirmProvider, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, type LlmCapability, type LlmDriver, type LlmField, type LlmFound, type LlmModel, type LlmProvider, type LlmProviderInput, type LlmPullProgress, LlmSettings, type LlmSettingsApi, type LlmSettingsLabels, type LlmSlot, type LlmState, type McpCall, type McpClient, McpSettings, type McpSettingsApi, type McpSettingsLabels, type McpStatus, type McpTool, OptionPicker, type OptionPickerLabels, PLATES, Panel, PanelCard, type PanelCardProps, type PanelItemProps, type PickOption, type Plate, PlatePicker, type PlatePickerProps, PreferenceScript, TreeExpander, type TreeExpanderProps, TreeIcon, type TreeIconProps, TreeLabel, type TreeLabelProps, TreeLines, TreeNode, TreeNodeContent, type TreeNodeContentProps, type TreeNodeProps, TreeNodeTrigger, type TreeNodeTriggerProps, TreeProvider, type TreeProviderProps, TreeView, type TreeViewProps, TzPicker, type TzPickerLabels, type TzPickerProps, derivePlate, isPlate, useCompact, useConfirm, useFormField, usePlate };
|
package/dist/blocks/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { Label, Combobox, ComboboxInput, ComboboxContent, ComboboxEmpty, ComboboxList, ComboboxItem, Spinner, Alert, AlertDescription, FieldGroup, FieldSet, FieldLegend, FieldDescription, Field, FieldContent, FieldLabel, Badge, Switch, FieldSeparator, Progress } from '../chunk-
|
|
2
|
+
import { Label, Combobox, ComboboxInput, ComboboxContent, ComboboxEmpty, ComboboxList, ComboboxItem, Spinner, Alert, AlertDescription, FieldGroup, FieldSet, FieldLegend, FieldDescription, Field, FieldContent, FieldLabel, Badge, Switch, FieldSeparator, Progress, RadioGroup } from '../chunk-EJP7F42V.js';
|
|
3
3
|
import { NativeSelect, NativeSelectOption } from '../chunk-FHM6VOPQ.js';
|
|
4
4
|
import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter } from '../chunk-XJJQAQWJ.js';
|
|
5
5
|
import { Dialog, DialogOverlay, DialogContent, DialogTitle, DialogDescription } from '../chunk-XWGYXLIA.js';
|
|
@@ -7,11 +7,10 @@ import '../chunk-2HDU26FC.js';
|
|
|
7
7
|
import { Button, Input } from '../chunk-VGOGWZCF.js';
|
|
8
8
|
import { cn } from '../chunk-XH55BHUU.js';
|
|
9
9
|
import * as React5 from 'react';
|
|
10
|
-
import { createContext,
|
|
11
|
-
import { Slot } from 'radix-ui';
|
|
10
|
+
import { createContext, useState, useContext, useCallback, useId, useSyncExternalStore, useEffect } from 'react';
|
|
11
|
+
import { Slot, RadioGroup as RadioGroup$1 } from 'radix-ui';
|
|
12
12
|
import { FormProvider, Controller, useFormContext } from 'react-hook-form';
|
|
13
13
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
14
|
-
import { useRouter, useSearchParams } from 'next/navigation';
|
|
15
14
|
import { ChevronRight, CheckIcon, CopyIcon, PlusIcon, FolderOpen, Folder, File } from 'lucide-react';
|
|
16
15
|
|
|
17
16
|
var Form = FormProvider;
|
|
@@ -73,33 +72,15 @@ function FormMessage({ className, ...props }) {
|
|
|
73
72
|
}
|
|
74
73
|
return /* @__PURE__ */ jsx("p", { "data-slot": "form-message", id: formMessageId, className: cn("text-destructive text-sm", className), ...props, children: body });
|
|
75
74
|
}
|
|
76
|
-
function Panel({
|
|
77
|
-
const
|
|
78
|
-
const params = useSearchParams();
|
|
79
|
-
const defaultKey = items[0]?.key;
|
|
80
|
-
const panelKey = useMemo(() => `panel${name ? "-" + name : ""}`, [name]);
|
|
81
|
-
const panelFromUrl = useMemo(() => {
|
|
82
|
-
if (!enable_url) return defaultKey;
|
|
83
|
-
return params.get(panelKey) ?? defaultKey;
|
|
84
|
-
}, [enable_url, params, defaultKey, panelKey]);
|
|
85
|
-
const [active, setActive] = useState(panelFromUrl);
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
if (!enable_url) return;
|
|
88
|
-
setActive(panelFromUrl);
|
|
89
|
-
}, [panelFromUrl, enable_url]);
|
|
75
|
+
function Panel({ items }) {
|
|
76
|
+
const [active, setActive] = useState(items[0]?.key);
|
|
90
77
|
const current = items.find((s) => s.key === active) ?? items[0];
|
|
91
78
|
if (!current) return null;
|
|
92
|
-
const navigate = (key) => {
|
|
93
|
-
if (key === active) return;
|
|
94
|
-
setActive(key);
|
|
95
|
-
if (!enable_url) return;
|
|
96
|
-
router.replace(`?${panelKey}=${key}`, { scroll: false });
|
|
97
|
-
};
|
|
98
79
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-6 h-full min-h-0 flex flex-col", children: [
|
|
99
80
|
/* @__PURE__ */ jsx("div", { className: "lg:hidden", children: /* @__PURE__ */ jsx("div", { className: "inline-flex rounded-lg bg-muted p-1", children: items?.map((s) => /* @__PURE__ */ jsx(
|
|
100
81
|
"button",
|
|
101
82
|
{
|
|
102
|
-
onClick: () =>
|
|
83
|
+
onClick: () => setActive(s.key),
|
|
103
84
|
className: cn(
|
|
104
85
|
"rounded-md px-3 py-1.5 text-sm transition-all",
|
|
105
86
|
active === s.key ? "bg-background text-foreground shadow-sm" : s.danger ? "text-destructive" : "text-muted-foreground hover:text-foreground"
|
|
@@ -113,7 +94,7 @@ function Panel({ name, items, enable_url }) {
|
|
|
113
94
|
s.key
|
|
114
95
|
)) }) }),
|
|
115
96
|
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-8 lg:grid-cols-[240px_1fr] flex-1 min-h-0", children: [
|
|
116
|
-
/* @__PURE__ */ jsx("aside", { className: "hidden space-y-1 lg:block overflow-y-auto min-h-0 pr-1 [overflow:overlay]", children: items?.map((s) => /* @__PURE__ */ jsx(PanelItem, { active: active === s.key, icon: s.icon, danger: s.danger, hasError: s.hasError, onClick: () =>
|
|
97
|
+
/* @__PURE__ */ jsx("aside", { className: "hidden space-y-1 lg:block overflow-y-auto min-h-0 pr-1 [overflow:overlay]", children: items?.map((s) => /* @__PURE__ */ jsx(PanelItem, { active: active === s.key, icon: s.icon, danger: s.danger, hasError: s.hasError, onClick: () => setActive(s.key), children: s.label }, s.key)) }),
|
|
117
98
|
/* @__PURE__ */ jsx("div", { className: "space-y-6 overflow-y-auto min-h-0 pr-1 [overflow:overlay]", children: current.content })
|
|
118
99
|
] })
|
|
119
100
|
] });
|
|
@@ -1163,6 +1144,7 @@ function LlmSettings({
|
|
|
1163
1144
|
] })
|
|
1164
1145
|
] }),
|
|
1165
1146
|
slot.error ? /* @__PURE__ */ jsx("p", { className: "text-destructive text-xs", children: slot.error }) : null,
|
|
1147
|
+
api.slotNote?.(slot.name),
|
|
1166
1148
|
current?.manages && api.pull && missing && !pulling ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-3", children: [
|
|
1167
1149
|
/* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-xs", children: t.notDownloaded }),
|
|
1168
1150
|
/* @__PURE__ */ jsxs(
|
|
@@ -1302,6 +1284,154 @@ function LlmSettings({
|
|
|
1302
1284
|
);
|
|
1303
1285
|
}
|
|
1304
1286
|
|
|
1305
|
-
|
|
1287
|
+
// src/blocks/plate.ts
|
|
1288
|
+
var PLATES = [
|
|
1289
|
+
"pink",
|
|
1290
|
+
"rose",
|
|
1291
|
+
"crimson",
|
|
1292
|
+
"rust",
|
|
1293
|
+
"orange",
|
|
1294
|
+
"ochre",
|
|
1295
|
+
"amber",
|
|
1296
|
+
"honey",
|
|
1297
|
+
"gold",
|
|
1298
|
+
"olive",
|
|
1299
|
+
"lime",
|
|
1300
|
+
"green",
|
|
1301
|
+
"teal",
|
|
1302
|
+
"cyan",
|
|
1303
|
+
"azure",
|
|
1304
|
+
"blue",
|
|
1305
|
+
"indigo",
|
|
1306
|
+
"violet",
|
|
1307
|
+
"magenta"
|
|
1308
|
+
];
|
|
1309
|
+
var BEARING_PLATES = [
|
|
1310
|
+
"pink",
|
|
1311
|
+
"rust",
|
|
1312
|
+
"amber",
|
|
1313
|
+
"olive",
|
|
1314
|
+
"green",
|
|
1315
|
+
"teal",
|
|
1316
|
+
"azure",
|
|
1317
|
+
"blue",
|
|
1318
|
+
"violet"
|
|
1319
|
+
];
|
|
1320
|
+
function isPlate(s) {
|
|
1321
|
+
return PLATES.includes(s);
|
|
1322
|
+
}
|
|
1323
|
+
function derivePlate(id) {
|
|
1324
|
+
let h = 2166136261;
|
|
1325
|
+
for (let i = 0; i < id.length; i++) {
|
|
1326
|
+
h ^= id.charCodeAt(i);
|
|
1327
|
+
h = Math.imul(h, 16777619) >>> 0;
|
|
1328
|
+
}
|
|
1329
|
+
return BEARING_PLATES[h % BEARING_PLATES.length];
|
|
1330
|
+
}
|
|
1331
|
+
var NONE = "none";
|
|
1332
|
+
function PlatePicker({ value, onChange, label, resetLabel, plateLabels, className }) {
|
|
1333
|
+
const swatch = "size-7 shrink-0 rounded-none border outline-2 -outline-offset-[3px] outline-transparent focus-visible:ring-2 focus-visible:ring-ring";
|
|
1334
|
+
return /* @__PURE__ */ jsxs(
|
|
1335
|
+
RadioGroup,
|
|
1336
|
+
{
|
|
1337
|
+
"aria-label": label,
|
|
1338
|
+
value: value ?? NONE,
|
|
1339
|
+
onValueChange: (v) => onChange(isPlate(v) ? v : null),
|
|
1340
|
+
className: cn("flex w-auto flex-wrap gap-2", className),
|
|
1341
|
+
children: [
|
|
1342
|
+
/* @__PURE__ */ jsx(
|
|
1343
|
+
RadioGroup$1.Item,
|
|
1344
|
+
{
|
|
1345
|
+
value: NONE,
|
|
1346
|
+
"aria-label": resetLabel,
|
|
1347
|
+
title: resetLabel,
|
|
1348
|
+
className: cn(swatch, "bg-muted border-border data-checked:outline-foreground")
|
|
1349
|
+
}
|
|
1350
|
+
),
|
|
1351
|
+
PLATES.map((p) => /* @__PURE__ */ jsx(
|
|
1352
|
+
RadioGroup$1.Item,
|
|
1353
|
+
{
|
|
1354
|
+
value: p,
|
|
1355
|
+
"aria-label": plateLabels?.[p] ?? p,
|
|
1356
|
+
title: plateLabels?.[p] ?? p,
|
|
1357
|
+
"data-plate": p,
|
|
1358
|
+
className: cn(swatch, "bg-primary border-transparent data-checked:outline-primary-foreground")
|
|
1359
|
+
},
|
|
1360
|
+
p
|
|
1361
|
+
))
|
|
1362
|
+
]
|
|
1363
|
+
}
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
var PLATE_KEY = "lyra.plate";
|
|
1367
|
+
var COMPACT_KEY = "lyra.compact";
|
|
1368
|
+
var listeners = /* @__PURE__ */ new Map();
|
|
1369
|
+
function read(key) {
|
|
1370
|
+
try {
|
|
1371
|
+
return localStorage.getItem(key);
|
|
1372
|
+
} catch {
|
|
1373
|
+
return null;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
function useStoredSetting(key) {
|
|
1377
|
+
const subscribe = useCallback(
|
|
1378
|
+
(onChange) => {
|
|
1379
|
+
const set = listeners.get(key) ?? /* @__PURE__ */ new Set();
|
|
1380
|
+
listeners.set(key, set);
|
|
1381
|
+
set.add(onChange);
|
|
1382
|
+
const onStorage = (e) => {
|
|
1383
|
+
if (e.key === key) onChange();
|
|
1384
|
+
};
|
|
1385
|
+
window.addEventListener("storage", onStorage);
|
|
1386
|
+
return () => {
|
|
1387
|
+
set.delete(onChange);
|
|
1388
|
+
window.removeEventListener("storage", onStorage);
|
|
1389
|
+
};
|
|
1390
|
+
},
|
|
1391
|
+
[key]
|
|
1392
|
+
);
|
|
1393
|
+
const value = useSyncExternalStore(
|
|
1394
|
+
subscribe,
|
|
1395
|
+
() => read(key),
|
|
1396
|
+
() => null
|
|
1397
|
+
);
|
|
1398
|
+
const store = useCallback((next) => {
|
|
1399
|
+
try {
|
|
1400
|
+
if (next === null) localStorage.removeItem(key);
|
|
1401
|
+
else localStorage.setItem(key, next);
|
|
1402
|
+
} catch {
|
|
1403
|
+
}
|
|
1404
|
+
listeners.get(key)?.forEach((l) => l());
|
|
1405
|
+
}, [key]);
|
|
1406
|
+
return [value, store];
|
|
1407
|
+
}
|
|
1408
|
+
function useRootAttribute(name, value) {
|
|
1409
|
+
useEffect(() => {
|
|
1410
|
+
const root = document.documentElement;
|
|
1411
|
+
if (value === null) root.removeAttribute(name);
|
|
1412
|
+
else root.setAttribute(name, value);
|
|
1413
|
+
}, [name, value]);
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
// src/blocks/use-plate.ts
|
|
1417
|
+
function usePlate() {
|
|
1418
|
+
const [stored, store] = useStoredSetting(PLATE_KEY);
|
|
1419
|
+
const plate = stored !== null && isPlate(stored) ? stored : null;
|
|
1420
|
+
useRootAttribute("data-plate", plate);
|
|
1421
|
+
return [plate, store];
|
|
1422
|
+
}
|
|
1423
|
+
function useCompact() {
|
|
1424
|
+
const [stored, store] = useStoredSetting(COMPACT_KEY);
|
|
1425
|
+
const compact = stored === "true";
|
|
1426
|
+
const setCompact = useCallback((next) => store(next ? "true" : null), [store]);
|
|
1427
|
+
useRootAttribute("data-compact", compact ? "true" : null);
|
|
1428
|
+
return [compact, setCompact];
|
|
1429
|
+
}
|
|
1430
|
+
var SCRIPT = `try{var d=document.documentElement,p=localStorage.getItem("${PLATE_KEY}");if(p)d.setAttribute("data-plate",p);if(localStorage.getItem("${COMPACT_KEY}")==="true")d.setAttribute("data-compact","true")}catch(e){}`;
|
|
1431
|
+
function PreferenceScript() {
|
|
1432
|
+
return /* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: SCRIPT } });
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
export { BEARING_PLATES, ConfirmContext, ConfirmDialog, ConfirmProvider, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, LlmSettings, McpSettings, OptionPicker, PLATES, Panel, PanelCard, PlatePicker, PreferenceScript, TreeExpander, TreeIcon, TreeLabel, TreeLines, TreeNode, TreeNodeContent, TreeNodeTrigger, TreeProvider, TreeView, TzPicker, derivePlate, isPlate, useCompact, useConfirm, useFormField, usePlate };
|
|
1306
1436
|
//# sourceMappingURL=index.js.map
|
|
1307
1437
|
//# sourceMappingURL=index.js.map
|