@tradalab/lyra 3.17.0 → 3.19.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.
@@ -1,35 +1,40 @@
1
1
  "use client";
2
- import { Label, Badge, Combobox, ComboboxInput, ComboboxContent, ComboboxEmpty, ComboboxList, ComboboxItem, Drawer, DrawerTrigger, DrawerContent, DrawerHeader, DrawerTitle, DrawerDescription, Spinner, Alert, AlertDescription, FieldGroup, FieldSet, FieldLegend, FieldDescription, Field, FieldContent, FieldLabel, FieldSeparator, Progress } from '../chunk-ASSRDIKG.js';
2
+ import { Label, Badge, Spinner, Select, SelectTrigger, SelectValue, SelectContent, SelectItem, Combobox, ComboboxInput, ComboboxContent, ComboboxEmpty, ComboboxList, ComboboxItem, Drawer, DrawerTrigger, DrawerContent, DrawerHeader, DrawerTitle, DrawerDescription, Calendar, Alert, AlertDescription, FieldGroup, FieldSet, FieldLegend, FieldDescription, Field, FieldContent, FieldLabel, FieldSeparator, Progress } from '../chunk-ASSRDIKG.js';
3
3
  export { PreferenceScript } from '../chunk-ASSRDIKG.js';
4
4
  import { NativeSelect, NativeSelectOption } from '../chunk-KSF233MC.js';
5
- export { useCompact, usePlate } from '../chunk-AIULLZYM.js';
6
- import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter, RadioGroup, RadioGroupItem, Switch } from '../chunk-UNRT3B6P.js';
5
+ import { useBackClose } from '../chunk-W3J2KTYP.js';
6
+ export { useCompact, usePlate } from '../chunk-W3J2KTYP.js';
7
+ import { Card, CardHeader, CardTitle, CardDescription, CardContent, CardFooter, SidebarGroupContent, SidebarMenu, SidebarContent, SidebarGroup, Switch, RadioGroup, RadioGroupItem } from '../chunk-UNRT3B6P.js';
7
8
  export { PlatePicker } from '../chunk-UNRT3B6P.js';
8
9
  export { BEARING_PLATES, PLATES, derivePlate, isPlate } from '../chunk-D7DMRCDY.js';
9
10
  import '../chunk-OH3OMK7A.js';
10
- import { isConnectionColor, CONNECTION_COLOR_NAMES, CONNECTION_COLORS, addTag } from '../chunk-A3T2BEQH.js';
11
- import { Dialog, DialogOverlay, DialogContent, DialogTitle, DialogDescription } from '../chunk-L4LQCVOF.js';
11
+ import { isConnectionColor, CONNECTION_COLOR_NAMES, CONNECTION_COLORS, addTag, matchesKeyword } from '../chunk-A3T2BEQH.js';
12
+ import { Dialog, DialogOverlay, DialogContent, DialogTitle, DialogDescription, DialogHeader, DialogFooter, Popover, PopoverTrigger, PopoverContent } from '../chunk-L4LQCVOF.js';
12
13
  import { foldText } from '../chunk-5XFDQRXV.js';
13
- import { Avatar, AvatarImage, AvatarFallback } from '../chunk-VXW3K5O5.js';
14
+ import { Textarea, InputGroup, InputGroupInput, InputGroupAddon, Avatar, AvatarImage, AvatarFallback, InputGroupButton } from '../chunk-VXW3K5O5.js';
14
15
  import { Button, Input } from '../chunk-VGOGWZCF.js';
15
16
  import { cn } from '../chunk-XH55BHUU.js';
16
- import * as React5 from 'react';
17
- import { createContext, useState, useContext, useCallback, useMemo, useId } from 'react';
17
+ import * as React6 from 'react';
18
+ import { createContext, useState, useRef, useMemo, useContext, useCallback, useId, createElement, useEffect } from 'react';
18
19
  import { Slot } from 'radix-ui';
19
20
  import { FormProvider, Controller, useFormContext } from 'react-hook-form';
20
21
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
21
- import { ChevronRight, XIcon, CheckIcon, CopyIcon, RefreshCwIcon, PlusIcon, ListIcon, FolderOpen, Folder, File } from 'lucide-react';
22
+ import { ChevronRight, XIcon, PlusIcon, Trash2Icon, PlugIcon, SaveIcon, LockIcon, CheckIcon, CopyIcon, RefreshCwIcon, ListIcon, CalendarIcon, FolderOpen, Folder, File } from 'lucide-react';
23
+ import { format } from 'date-fns';
24
+ import { enUS } from 'date-fns/locale/en-US';
25
+ import { ja } from 'date-fns/locale/ja';
26
+ import { vi } from 'date-fns/locale/vi';
22
27
 
23
28
  var Form = FormProvider;
24
- var FormFieldContext = React5.createContext(null);
29
+ var FormFieldContext = React6.createContext(null);
25
30
  var FormField = ({
26
31
  ...props
27
32
  }) => {
28
33
  return /* @__PURE__ */ jsx(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ jsx(Controller, { ...props }) });
29
34
  };
30
35
  var useFormField = () => {
31
- const fieldContext = React5.useContext(FormFieldContext);
32
- const itemContext = React5.useContext(FormItemContext);
36
+ const fieldContext = React6.useContext(FormFieldContext);
37
+ const itemContext = React6.useContext(FormItemContext);
33
38
  const { getFieldState, formState } = useFormContext();
34
39
  if (!fieldContext) {
35
40
  throw new Error("useFormField should be used within <FormField>");
@@ -45,9 +50,9 @@ var useFormField = () => {
45
50
  ...fieldState
46
51
  };
47
52
  };
48
- var FormItemContext = React5.createContext(null);
53
+ var FormItemContext = React6.createContext(null);
49
54
  function FormItem({ className, ...props }) {
50
- const id = React5.useId();
55
+ const id = React6.useId();
51
56
  return /* @__PURE__ */ jsx(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ jsx("div", { "data-slot": "form-item", className: cn("grid gap-2", className), ...props }) });
52
57
  }
53
58
  function FormLabel({ className, ...props }) {
@@ -87,6 +92,7 @@ function Panel({ items }) {
87
92
  /* @__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(
88
93
  "button",
89
94
  {
95
+ type: "button",
90
96
  onClick: () => setActive(s.key),
91
97
  className: cn(
92
98
  "rounded-md px-3 py-1.5 text-sm transition-all",
@@ -138,31 +144,95 @@ function PanelCard({ title, description, hint, action, children }) {
138
144
  ] })
139
145
  ] });
140
146
  }
147
+ var shell = cn("fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2", "p-4 w-[min(400px,calc(100vw-2rem))]", "focus:outline-none");
148
+ function Lines({ items }) {
149
+ return /* @__PURE__ */ jsx("ul", { className: "mt-2 list-disc space-y-1 pl-5 text-sm", children: items.map((item, i) => /* @__PURE__ */ jsx("li", { children: item }, i)) });
150
+ }
141
151
  function ConfirmDialog({ options, onConfirm, onCancel }) {
152
+ const [reason, setReason] = useState("");
153
+ const missing = !!options.reason?.required && reason.trim() === "";
142
154
  return /* @__PURE__ */ jsxs(Dialog, { open: true, onOpenChange: (val) => !val && onCancel(), children: [
143
155
  /* @__PURE__ */ jsx(DialogOverlay, { className: "fixed inset-0 bg-white/10" }),
144
- /* @__PURE__ */ jsxs(DialogContent, { className: cn("fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2", "p-4 w-[400px]", "focus:outline-none"), children: [
156
+ /* @__PURE__ */ jsxs(DialogContent, { className: shell, children: [
145
157
  /* @__PURE__ */ jsx(DialogTitle, { className: "text-sm font-medium", children: options.title }),
146
158
  options.description != null && /* @__PURE__ */ jsx(DialogDescription, { asChild: true, children: /* @__PURE__ */ jsx("div", { className: "mt-2 text-sm text-muted-foreground", children: options.description }) }),
147
- /* @__PURE__ */ jsxs("div", { className: "mt-2 flex justify-end gap-2", children: [
159
+ options.consequences && options.consequences.length > 0 && /* @__PURE__ */ jsx(Lines, { items: options.consequences }),
160
+ options.reversible != null && /* @__PURE__ */ jsx("p", { className: cn("mt-2 text-xs", options.reversible ? "text-muted-foreground" : "text-destructive"), children: options.reversible ? options.reversibleText ?? "This can be undone." : options.irreversibleText ?? "This cannot be undone." }),
161
+ options.reason && /* @__PURE__ */ jsxs("label", { className: "mt-3 grid gap-1.5 text-sm", children: [
162
+ /* @__PURE__ */ jsx("span", { children: options.reason.label }),
163
+ /* @__PURE__ */ jsx(Textarea, { value: reason, placeholder: options.reason.placeholder, onChange: (e) => setReason(e.target.value), rows: 3 })
164
+ ] }),
165
+ /* @__PURE__ */ jsxs("div", { className: "mt-3 flex justify-end gap-2", children: [
148
166
  /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: onCancel, children: options.cancelText ?? "Cancel" }),
149
- /* @__PURE__ */ jsx(Button, { size: "sm", onClick: onConfirm, className: cn(options.danger && "bg-red-600 hover:bg-red-700 text-white"), children: options.confirmText ?? "Confirm" })
167
+ /* @__PURE__ */ jsx(
168
+ Button,
169
+ {
170
+ size: "sm",
171
+ disabled: missing,
172
+ onClick: () => onConfirm(reason.trim()),
173
+ className: cn(options.danger && "bg-red-600 hover:bg-red-700 text-white"),
174
+ children: options.confirmText ?? "Confirm"
175
+ }
176
+ )
177
+ ] })
178
+ ] })
179
+ ] });
180
+ }
181
+ function BlockedDialog({ options, onClose }) {
182
+ return /* @__PURE__ */ jsxs(Dialog, { open: true, onOpenChange: (val) => !val && onClose(), children: [
183
+ /* @__PURE__ */ jsx(DialogOverlay, { className: "fixed inset-0 bg-white/10" }),
184
+ /* @__PURE__ */ jsxs(DialogContent, { className: shell, children: [
185
+ /* @__PURE__ */ jsx(DialogTitle, { className: "text-sm font-medium", children: options.title }),
186
+ options.description != null && /* @__PURE__ */ jsx(DialogDescription, { asChild: true, children: /* @__PURE__ */ jsx("div", { className: "mt-2 text-sm text-muted-foreground", children: options.description }) }),
187
+ /* @__PURE__ */ jsx(Lines, { items: options.blockers }),
188
+ /* @__PURE__ */ jsxs("div", { className: "mt-3 flex justify-end gap-2", children: [
189
+ /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: onClose, children: options.closeText ?? "Close" }),
190
+ options.action && /* @__PURE__ */ jsx(
191
+ Button,
192
+ {
193
+ size: "sm",
194
+ onClick: () => {
195
+ onClose();
196
+ options.action.onClick();
197
+ },
198
+ children: options.action.label
199
+ }
200
+ )
150
201
  ] })
151
202
  ] })
152
203
  ] });
153
204
  }
154
205
  var ConfirmContext = createContext(null);
206
+ var ConfirmReasonContext = createContext(null);
207
+ var BlockedContext = createContext(null);
155
208
  function ConfirmProvider({ children }) {
156
209
  const [state, setState] = useState(null);
157
- const confirm = (options) => new Promise((resolve) => setState({ options, resolve }));
158
- const close = (result) => {
159
- state?.resolve(result);
210
+ const open = useRef(null);
211
+ const next = useRef(0);
212
+ const { confirm, confirmReason, blocked } = useMemo(() => {
213
+ const show = (o) => {
214
+ open.current?.dismiss();
215
+ open.current = o;
216
+ setState(o);
217
+ };
218
+ const confirm2 = (options) => new Promise((resolve) => show({ id: ++next.current, kind: "confirm", options, resolve, dismiss: () => resolve(false) }));
219
+ const confirmReason2 = (options) => new Promise(
220
+ (resolve) => show({ id: ++next.current, kind: "reason", options, resolve, dismiss: () => resolve(null) })
221
+ );
222
+ const blocked2 = (options) => new Promise((resolve) => show({ id: ++next.current, kind: "blocked", options, resolve, dismiss: () => resolve() }));
223
+ return { confirm: confirm2, confirmReason: confirmReason2, blocked: blocked2 };
224
+ }, []);
225
+ const done = (fn) => {
226
+ fn();
227
+ open.current = null;
160
228
  setState(null);
161
229
  };
162
- return /* @__PURE__ */ jsxs(ConfirmContext.Provider, { value: confirm, children: [
230
+ return /* @__PURE__ */ jsx(ConfirmContext.Provider, { value: confirm, children: /* @__PURE__ */ jsx(ConfirmReasonContext.Provider, { value: confirmReason, children: /* @__PURE__ */ jsxs(BlockedContext.Provider, { value: blocked, children: [
163
231
  children,
164
- state && /* @__PURE__ */ jsx(ConfirmDialog, { options: state.options, onConfirm: () => close(true), onCancel: () => close(false) })
165
- ] });
232
+ state?.kind === "confirm" && /* @__PURE__ */ jsx(ConfirmDialog, { options: state.options, onConfirm: () => done(() => state.resolve(true)), onCancel: () => done(() => state.resolve(false)) }, state.id),
233
+ state?.kind === "reason" && /* @__PURE__ */ jsx(ConfirmDialog, { options: state.options, onConfirm: (r) => done(() => state.resolve(r)), onCancel: () => done(() => state.resolve(null)) }, state.id),
234
+ state?.kind === "blocked" && /* @__PURE__ */ jsx(BlockedDialog, { options: state.options, onClose: () => done(() => state.resolve()) }, state.id)
235
+ ] }) }) });
166
236
  }
167
237
  var useConfirm = () => {
168
238
  const ctx = useContext(ConfirmContext);
@@ -171,6 +241,20 @@ var useConfirm = () => {
171
241
  }
172
242
  return ctx;
173
243
  };
244
+ var useConfirmReason = () => {
245
+ const ctx = useContext(ConfirmReasonContext);
246
+ if (!ctx) {
247
+ throw new Error("useConfirmReason must be used inside ConfirmProvider");
248
+ }
249
+ return ctx;
250
+ };
251
+ var useBlocked = () => {
252
+ const ctx = useContext(BlockedContext);
253
+ if (!ctx) {
254
+ throw new Error("useBlocked must be used inside ConfirmProvider");
255
+ }
256
+ return ctx;
257
+ };
174
258
 
175
259
  // src/blocks/tree/data.ts
176
260
  var DIGITS = /\d+/g;
@@ -722,6 +806,696 @@ function TagInput({ value, onChange, suggestions = [], placeholder, removeLabel,
722
806
  }
723
807
  );
724
808
  }
809
+
810
+ // src/blocks/connection/tree-data.ts
811
+ var collator = new Intl.Collator(void 0, { numeric: true, sensitivity: "base" });
812
+ function bySortOrder(a, b) {
813
+ return (a.sort_order ?? 0) - (b.sort_order ?? 0) || collator.compare(a.name, b.name);
814
+ }
815
+ function buildConnectionTree(groups, connections) {
816
+ const sorted = [...connections].sort(bySortOrder);
817
+ const known = new Set(groups.map((g) => g.id));
818
+ const leaf = (c, level) => ({ id: c.id, name: c.name, level, isGroup: false, connection: c });
819
+ const grouped = [...groups].sort(bySortOrder).map((g) => ({
820
+ id: g.id,
821
+ name: g.name,
822
+ level: 0,
823
+ isGroup: true,
824
+ group: g,
825
+ children: sorted.filter((c) => c.group_id === g.id).map((c) => leaf(c, 1))
826
+ }));
827
+ const loose = sorted.filter((c) => !c.group_id || !known.has(c.group_id)).map((c) => leaf(c, 0));
828
+ return [...grouped, ...loose];
829
+ }
830
+ function connectionNameMatches(item, keyword) {
831
+ return matchesKeyword([item.name], keyword);
832
+ }
833
+ function ConnectionTree({
834
+ groups,
835
+ connections,
836
+ keyword = "",
837
+ matches = connectionNameMatches,
838
+ storageKey,
839
+ activeId,
840
+ onOpen,
841
+ onDrop,
842
+ icon,
843
+ iconClassName,
844
+ badges,
845
+ actions,
846
+ className
847
+ }) {
848
+ const tree = useMemo(() => buildConnectionTree(groups, connections), [groups, connections]);
849
+ const filtering = keyword.trim() !== "";
850
+ const shown = useMemo(() => filtering ? filterTree(tree, (i) => matches(i, keyword)) : tree, [tree, filtering, matches, keyword]);
851
+ const members = useMemo(() => new Map(tree.filter((i) => i.isGroup).map((g) => [g.id, g.children?.map((c) => c.id) ?? []])), [tree]);
852
+ const [expanded, setExpanded] = useState(() => loadExpanded(storageKey));
853
+ const [whileFiltering, setWhileFiltering] = useState(null);
854
+ const [selected, setSelected] = useState([]);
855
+ const shownExpanded = useMemo(() => {
856
+ if (!filtering) return expanded;
857
+ if (whileFiltering?.keyword === keyword) return whileFiltering.ids;
858
+ return new Set(shown.filter((i) => i.isGroup).map((i) => i.id));
859
+ }, [filtering, keyword, whileFiltering, shown, expanded]);
860
+ const onExpandedChange = useCallback(
861
+ (ids) => {
862
+ if (filtering) {
863
+ setWhileFiltering({ keyword, ids });
864
+ return;
865
+ }
866
+ setExpanded(ids);
867
+ saveExpanded(storageKey, ids);
868
+ },
869
+ [filtering, keyword, storageKey]
870
+ );
871
+ const drop = useCallback(
872
+ (plan) => {
873
+ if (plan.kind === "leaf" && plan.groupId && !expanded.has(plan.groupId)) {
874
+ const next = /* @__PURE__ */ new Set([...expanded, plan.groupId]);
875
+ setExpanded(next);
876
+ saveExpanded(storageKey, next);
877
+ }
878
+ void onDrop?.(plan);
879
+ },
880
+ [expanded, onDrop, storageKey]
881
+ );
882
+ return /* @__PURE__ */ jsx(TreeDndProvider, { tree, enabled: !filtering && !!onDrop, onDrop: drop, children: /* @__PURE__ */ jsx(DropArea, { className, children: /* @__PURE__ */ jsx(SidebarGroupContent, { children: /* @__PURE__ */ jsx(SidebarMenu, { children: /* @__PURE__ */ jsx(TreeProvider, { expandedIds: shownExpanded, onExpandedChange, selectedIds: selected, onSelectionChange: setSelected, multiSelect: true, children: /* @__PURE__ */ jsx(TreeView, { className: "px-1 py-2", children: shown.map((item) => /* @__PURE__ */ jsx(
883
+ Node,
884
+ {
885
+ item,
886
+ members,
887
+ activeId,
888
+ onOpen,
889
+ icon,
890
+ iconClassName,
891
+ badges,
892
+ actions
893
+ },
894
+ item.id
895
+ )) }) }) }) }) }) });
896
+ }
897
+ function DropArea({ className, children }) {
898
+ const root = useTreeDndRoot();
899
+ return /* @__PURE__ */ jsx(SidebarContent, { className: cn(root.className, className), ...root.rootProps, children: /* @__PURE__ */ jsx(SidebarGroup, { className: "p-0", ...root.treeProps, children }) });
900
+ }
901
+ function Node(props) {
902
+ const { item, members, activeId, onOpen, icon, iconClassName, badges, actions } = props;
903
+ const dnd = useTreeDndNode(item);
904
+ const connection = item.connection;
905
+ const open = !item.isGroup && connection && onOpen ? (e) => {
906
+ e.stopPropagation();
907
+ onOpen(connection);
908
+ } : void 0;
909
+ return /* @__PURE__ */ jsxs(TreeNode, { nodeId: item.id, level: item.level, isLast: item.level === 0, onDoubleClick: open, children: [
910
+ /* @__PURE__ */ jsxs(
911
+ TreeNodeTrigger,
912
+ {
913
+ "data-active": !item.isGroup && item.id === activeId ? "" : void 0,
914
+ className: cn("group/item px-1 py-1.5 data-[active]:bg-accent data-[active]:font-medium data-[active]:text-accent-foreground", dnd.className),
915
+ ...dnd.props,
916
+ children: [
917
+ /* @__PURE__ */ jsx(TreeExpander, { hasChildren: item.isGroup }),
918
+ /* @__PURE__ */ jsx(TreeIcon, { hasChildren: item.isGroup, icon: item.isGroup ? void 0 : icon?.(item), className: iconClassName?.(item) }),
919
+ /* @__PURE__ */ jsx(TreeLabel, { children: item.name }),
920
+ badges?.(item, members.get(item.id) ?? []),
921
+ actions && /* @__PURE__ */ jsx("span", { className: "ml-1 opacity-0 group-hover/item:opacity-100 focus-within:opacity-100", children: actions(item) })
922
+ ]
923
+ }
924
+ ),
925
+ item.isGroup && item.children && /* @__PURE__ */ jsx(TreeNodeContent, { hasChildren: true, children: item.children.map((child) => /* @__PURE__ */ createElement(Node, { ...props, key: child.id, item: child })) })
926
+ ] });
927
+ }
928
+ var DEFAULT_LABELS = { add: "Add", delete: "Delete", test: "Test connection", save: "Save" };
929
+ function ConfigListDialog({
930
+ open,
931
+ onOpenChange,
932
+ title,
933
+ items,
934
+ getId,
935
+ renderItem,
936
+ selectedId,
937
+ onSelect,
938
+ onAdd,
939
+ loading,
940
+ onSave,
941
+ onTest,
942
+ onDelete,
943
+ labels,
944
+ children,
945
+ className
946
+ }) {
947
+ const l = { ...DEFAULT_LABELS, ...labels };
948
+ const [busy, setBusy] = useState(() => /* @__PURE__ */ new Set());
949
+ const exec = async (action, handler) => {
950
+ if (!handler || busy.has(action)) return;
951
+ setBusy((prev) => new Set(prev).add(action));
952
+ try {
953
+ await handler();
954
+ } catch {
955
+ return;
956
+ } finally {
957
+ setBusy((prev) => {
958
+ const next = new Set(prev);
959
+ next.delete(action);
960
+ return next;
961
+ });
962
+ }
963
+ };
964
+ const run = (action, handler) => () => {
965
+ void exec(action, handler);
966
+ };
967
+ return /* @__PURE__ */ jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(
968
+ DialogContent,
969
+ {
970
+ className: cn("flex h-[85vh] flex-col p-0 sm:max-w-[700px]", className),
971
+ onInteractOutside: (e) => e.preventDefault(),
972
+ onEscapeKeyDown: (e) => e.preventDefault(),
973
+ children: [
974
+ /* @__PURE__ */ jsx(DialogHeader, { className: "px-4 pt-4", children: /* @__PURE__ */ jsx(DialogTitle, { className: "text-sm", children: title }) }),
975
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 overflow-hidden", children: [
976
+ /* @__PURE__ */ jsxs("div", { className: "flex w-[260px] flex-col border-r", children: [
977
+ /* @__PURE__ */ jsx("div", { className: "flex items-center gap-1 border-b p-2", children: /* @__PURE__ */ jsx(Button, { size: "icon", variant: "ghost", "aria-label": l.add, title: l.add, onClick: onAdd, children: /* @__PURE__ */ jsx(PlusIcon, { className: "h-4 w-4" }) }) }),
978
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 overflow-y-auto", role: "listbox", "aria-label": typeof title === "string" ? title : void 0, children: [
979
+ loading && /* @__PURE__ */ jsx("div", { className: "flex justify-center p-4", children: /* @__PURE__ */ jsx(Spinner, {}) }),
980
+ items.map((item) => {
981
+ const id = getId(item);
982
+ const active = id === selectedId;
983
+ return /* @__PURE__ */ jsx(
984
+ "button",
985
+ {
986
+ type: "button",
987
+ role: "option",
988
+ "aria-selected": active,
989
+ onClick: () => onSelect(item),
990
+ className: cn(
991
+ "block w-full cursor-pointer truncate border-l-2 px-3 py-2 text-left text-sm",
992
+ active ? "border-primary bg-muted" : "border-transparent hover:bg-muted"
993
+ ),
994
+ children: renderItem(item)
995
+ },
996
+ id
997
+ );
998
+ })
999
+ ] })
1000
+ ] }),
1001
+ /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1 overflow-auto p-4", children })
1002
+ ] }),
1003
+ selectedId !== void 0 && /* @__PURE__ */ jsxs(DialogFooter, { className: "flex gap-2 border-t p-2", children: [
1004
+ onDelete && /* @__PURE__ */ jsxs(Button, { size: "sm", variant: "destructive", disabled: busy.has("delete"), onClick: run("delete", onDelete), children: [
1005
+ busy.has("delete") ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsx(Trash2Icon, {}),
1006
+ l.delete
1007
+ ] }),
1008
+ onTest && /* @__PURE__ */ jsxs(Button, { size: "sm", variant: "outline", disabled: busy.has("test"), onClick: run("test", onTest), children: [
1009
+ busy.has("test") ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsx(PlugIcon, {}),
1010
+ l.test
1011
+ ] }),
1012
+ onSave && /* @__PURE__ */ jsxs(Button, { size: "sm", disabled: busy.has("save"), onClick: run("save", onSave), children: [
1013
+ busy.has("save") ? /* @__PURE__ */ jsx(Spinner, {}) : /* @__PURE__ */ jsx(SaveIcon, {}),
1014
+ l.save
1015
+ ] })
1016
+ ] })
1017
+ ]
1018
+ }
1019
+ ) });
1020
+ }
1021
+
1022
+ // src/blocks/connection/fields-common.ts
1023
+ function requiredRules(l) {
1024
+ return { required: l.required, validate: (v) => (typeof v === "string" ? v.trim() !== "" : v != null) || l.required };
1025
+ }
1026
+ function portRules(l) {
1027
+ return {
1028
+ required: l.required,
1029
+ validate: (v) => Number.isInteger(v) && v >= 1 && v <= 65535 || l.portRange
1030
+ };
1031
+ }
1032
+ function portInput(field) {
1033
+ return {
1034
+ name: field.name,
1035
+ type: "number",
1036
+ inputMode: "numeric",
1037
+ value: field.value ?? "",
1038
+ onBlur: field.onBlur,
1039
+ onChange: (e) => field.onChange(e.target.value === "" ? void 0 : Number(e.target.value))
1040
+ };
1041
+ }
1042
+ function optional(label, l) {
1043
+ return `${label} (${l.optional})`;
1044
+ }
1045
+ function proxyDefaults(p = {}) {
1046
+ return {
1047
+ id: p.id,
1048
+ protocol: p.protocol || "http",
1049
+ host: p.host ?? "",
1050
+ port: p.port || 8080,
1051
+ username: p.username ?? "",
1052
+ password: p.password ?? ""
1053
+ };
1054
+ }
1055
+ var DEFAULTS = {
1056
+ protocol: "Protocol",
1057
+ host: "Host",
1058
+ port: "Port",
1059
+ username: "Username",
1060
+ password: "Password",
1061
+ optional: "optional",
1062
+ required: "Required",
1063
+ portRange: "Between 1 and 65535"
1064
+ };
1065
+ function ProxyFields({
1066
+ form,
1067
+ labels,
1068
+ secretPlaceholder
1069
+ }) {
1070
+ const l = { ...DEFAULTS, ...labels };
1071
+ return /* @__PURE__ */ jsxs("div", { className: "space-y-4", children: [
1072
+ /* @__PURE__ */ jsx(
1073
+ FormField,
1074
+ {
1075
+ control: form.control,
1076
+ name: "protocol",
1077
+ rules: { required: l.required },
1078
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1079
+ /* @__PURE__ */ jsx(FormLabel, { children: l.protocol }),
1080
+ /* @__PURE__ */ jsxs(Select, { onValueChange: field.onChange, value: field.value, children: [
1081
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(SelectTrigger, { className: "w-full", children: /* @__PURE__ */ jsx(SelectValue, {}) }) }),
1082
+ /* @__PURE__ */ jsxs(SelectContent, { children: [
1083
+ /* @__PURE__ */ jsx(SelectItem, { value: "http", children: "HTTP" }),
1084
+ /* @__PURE__ */ jsx(SelectItem, { value: "socks5", children: "SOCKS5" })
1085
+ ] })
1086
+ ] }),
1087
+ /* @__PURE__ */ jsx(FormMessage, {})
1088
+ ] })
1089
+ }
1090
+ ),
1091
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-4 gap-4", children: [
1092
+ /* @__PURE__ */ jsx(
1093
+ FormField,
1094
+ {
1095
+ control: form.control,
1096
+ name: "host",
1097
+ rules: requiredRules(l),
1098
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { className: "col-span-3", children: [
1099
+ /* @__PURE__ */ jsx(FormLabel, { children: l.host }),
1100
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { placeholder: "127.0.0.1", ...field }) }),
1101
+ /* @__PURE__ */ jsx(FormMessage, {})
1102
+ ] })
1103
+ }
1104
+ ),
1105
+ /* @__PURE__ */ jsx(
1106
+ FormField,
1107
+ {
1108
+ control: form.control,
1109
+ name: "port",
1110
+ rules: portRules(l),
1111
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1112
+ /* @__PURE__ */ jsx(FormLabel, { children: l.port }),
1113
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { ...portInput(field) }) }),
1114
+ /* @__PURE__ */ jsx(FormMessage, {})
1115
+ ] })
1116
+ }
1117
+ )
1118
+ ] }),
1119
+ /* @__PURE__ */ jsx(
1120
+ FormField,
1121
+ {
1122
+ control: form.control,
1123
+ name: "username",
1124
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1125
+ /* @__PURE__ */ jsx(FormLabel, { children: optional(l.username, l) }),
1126
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { ...field, value: field.value ?? "", autoComplete: "off" }) })
1127
+ ] })
1128
+ }
1129
+ ),
1130
+ /* @__PURE__ */ jsx(
1131
+ FormField,
1132
+ {
1133
+ control: form.control,
1134
+ name: "password",
1135
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1136
+ /* @__PURE__ */ jsx(FormLabel, { children: optional(l.password, l) }),
1137
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { type: "password", ...field, value: field.value ?? "", placeholder: secretPlaceholder, autoComplete: "new-password" }) })
1138
+ ] })
1139
+ }
1140
+ )
1141
+ ] });
1142
+ }
1143
+ function tlsDefaults(t = {}) {
1144
+ return {
1145
+ id: t.id,
1146
+ name: t.name ?? "",
1147
+ verify: typeof t.verify === "boolean" ? t.verify : true,
1148
+ use_sni: Boolean(t.use_sni),
1149
+ server_name: t.server_name ?? "",
1150
+ ca_cert: t.ca_cert ?? "",
1151
+ client_auth: Boolean(t.client_auth),
1152
+ cert: t.cert ?? "",
1153
+ key: t.key ?? ""
1154
+ };
1155
+ }
1156
+ var DEFAULTS2 = {
1157
+ name: "Name",
1158
+ optional: "optional",
1159
+ verify: "Verify the server certificate",
1160
+ verifyHint: "Turn off only for a server with a self-signed certificate you trust.",
1161
+ useSni: "Send SNI",
1162
+ useSniHint: "Name the server in the handshake, for hosts that serve several certificates.",
1163
+ serverName: "Server name",
1164
+ caCert: "Root CA certificate",
1165
+ clientAuth: "Client certificate",
1166
+ clientAuthHint: "For servers that ask the client to prove who it is (mutual TLS).",
1167
+ clientCert: "Client certificate",
1168
+ clientKey: "Client private key"
1169
+ };
1170
+ var PEM_CERT = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----";
1171
+ var PEM_KEY = "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----";
1172
+ function TlsFields({
1173
+ form,
1174
+ labels,
1175
+ serverNamePlaceholder,
1176
+ secretPlaceholder
1177
+ }) {
1178
+ const l = { ...DEFAULTS2, ...labels };
1179
+ const verify = form.watch("verify");
1180
+ const useSni = form.watch("use_sni");
1181
+ const clientAuth = form.watch("client_auth");
1182
+ return /* @__PURE__ */ jsxs("div", { className: "grid gap-6 pb-4", children: [
1183
+ /* @__PURE__ */ jsx(
1184
+ FormField,
1185
+ {
1186
+ control: form.control,
1187
+ name: "name",
1188
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1189
+ /* @__PURE__ */ jsx(FormLabel, { children: `${l.name} (${l.optional})` }),
1190
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { ...field, value: field.value ?? "" }) })
1191
+ ] })
1192
+ }
1193
+ ),
1194
+ /* @__PURE__ */ jsxs("section", { className: "space-y-6 border p-4", children: [
1195
+ /* @__PURE__ */ jsx(Toggle, { form, name: "verify", label: l.verify, hint: l.verifyHint }),
1196
+ /* @__PURE__ */ jsx("hr", { className: "border-border" }),
1197
+ /* @__PURE__ */ jsx(Toggle, { form, name: "use_sni", label: l.useSni, hint: l.useSniHint }),
1198
+ (useSni || verify) && /* @__PURE__ */ jsx(
1199
+ FormField,
1200
+ {
1201
+ control: form.control,
1202
+ name: "server_name",
1203
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1204
+ /* @__PURE__ */ jsx(FormLabel, { children: l.serverName }),
1205
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { ...field, value: field.value ?? "", placeholder: serverNamePlaceholder }) }),
1206
+ /* @__PURE__ */ jsx(FormMessage, {})
1207
+ ] })
1208
+ }
1209
+ ),
1210
+ /* @__PURE__ */ jsx("hr", { className: "border-border" }),
1211
+ /* @__PURE__ */ jsx(Pem, { form, name: "ca_cert", label: l.caCert, placeholder: PEM_CERT })
1212
+ ] }),
1213
+ /* @__PURE__ */ jsxs("section", { className: "space-y-6 border p-4", children: [
1214
+ /* @__PURE__ */ jsx(Toggle, { form, name: "client_auth", label: l.clientAuth, hint: l.clientAuthHint }),
1215
+ clientAuth && /* @__PURE__ */ jsxs(Fragment, { children: [
1216
+ /* @__PURE__ */ jsx("hr", { className: "border-border" }),
1217
+ /* @__PURE__ */ jsx(Pem, { form, name: "cert", label: l.clientCert, placeholder: PEM_CERT }),
1218
+ /* @__PURE__ */ jsx(Pem, { form, name: "key", label: l.clientKey, placeholder: secretPlaceholder ?? PEM_KEY })
1219
+ ] })
1220
+ ] })
1221
+ ] });
1222
+ }
1223
+ function Toggle({ form, name, label, hint }) {
1224
+ return /* @__PURE__ */ jsx(
1225
+ FormField,
1226
+ {
1227
+ control: form.control,
1228
+ name,
1229
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { className: "flex items-center justify-between gap-4", children: [
1230
+ /* @__PURE__ */ jsxs("div", { children: [
1231
+ /* @__PURE__ */ jsx(FormLabel, { children: label }),
1232
+ /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: hint })
1233
+ ] }),
1234
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Switch, { checked: field.value, onCheckedChange: field.onChange }) })
1235
+ ] })
1236
+ }
1237
+ );
1238
+ }
1239
+ function Pem({ form, name, label, placeholder }) {
1240
+ return /* @__PURE__ */ jsx(
1241
+ FormField,
1242
+ {
1243
+ control: form.control,
1244
+ name,
1245
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1246
+ /* @__PURE__ */ jsx(FormLabel, { children: label }),
1247
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Textarea, { ...field, value: field.value ?? "", rows: 6, placeholder, className: "font-mono text-xs whitespace-pre" }) }),
1248
+ /* @__PURE__ */ jsx(FormMessage, {})
1249
+ ] })
1250
+ }
1251
+ );
1252
+ }
1253
+ function sshDefaults(s = {}) {
1254
+ return {
1255
+ id: s.id,
1256
+ host: s.host ?? "",
1257
+ port: s.port || 22,
1258
+ timeout: s.timeout || 60,
1259
+ username: s.username ?? "",
1260
+ kind: s.kind === "keypair" || s.kind === "agent" ? s.kind : "password",
1261
+ password: s.password ?? "",
1262
+ private_key: s.private_key ?? "",
1263
+ passphrase: s.passphrase ?? "",
1264
+ host_key: s.host_key ?? ""
1265
+ };
1266
+ }
1267
+ var DEFAULTS3 = {
1268
+ host: "Host",
1269
+ port: "Port",
1270
+ username: "Username",
1271
+ password: "Password",
1272
+ optional: "optional",
1273
+ required: "Required",
1274
+ portRange: "Between 1 and 65535",
1275
+ timeout: "Timeout (s)",
1276
+ kind: "Authentication",
1277
+ kindPassword: "Password",
1278
+ kindKeypair: "Key pair",
1279
+ kindAgent: "SSH agent",
1280
+ privateKey: "Private key",
1281
+ privateKeyPlaceholder: "-----BEGIN OPENSSH PRIVATE KEY-----",
1282
+ passphrase: "Passphrase",
1283
+ hostKey: "Host key",
1284
+ hostKeyUntrusted: "Not trusted yet",
1285
+ hostKeyHint: "Only the server holding this key is connected to. Test the connection to see the key it presents."
1286
+ };
1287
+ function SshFields({
1288
+ form,
1289
+ labels,
1290
+ kinds = ["password", "keypair", "agent"],
1291
+ secretPlaceholder,
1292
+ pinHostKey = false
1293
+ }) {
1294
+ const l = { ...DEFAULTS3, ...labels };
1295
+ const kind = form.watch("kind");
1296
+ const kindLabel = { password: l.kindPassword, keypair: l.kindKeypair, agent: l.kindAgent };
1297
+ usePinFollowsAddress(form, pinHostKey);
1298
+ return /* @__PURE__ */ jsxs("div", { className: "grid gap-4", children: [
1299
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-4 gap-4", children: [
1300
+ /* @__PURE__ */ jsx(
1301
+ FormField,
1302
+ {
1303
+ control: form.control,
1304
+ name: "host",
1305
+ rules: requiredRules(l),
1306
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { className: "col-span-3", children: [
1307
+ /* @__PURE__ */ jsx(FormLabel, { children: l.host }),
1308
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
1309
+ /* @__PURE__ */ jsx(FormMessage, {})
1310
+ ] })
1311
+ }
1312
+ ),
1313
+ /* @__PURE__ */ jsx(
1314
+ FormField,
1315
+ {
1316
+ control: form.control,
1317
+ name: "port",
1318
+ rules: portRules(l),
1319
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1320
+ /* @__PURE__ */ jsx(FormLabel, { children: l.port }),
1321
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { ...portInput(field) }) }),
1322
+ /* @__PURE__ */ jsx(FormMessage, {})
1323
+ ] })
1324
+ }
1325
+ )
1326
+ ] }),
1327
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-4 gap-4", children: [
1328
+ /* @__PURE__ */ jsx(
1329
+ FormField,
1330
+ {
1331
+ control: form.control,
1332
+ name: "username",
1333
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { className: "col-span-3", children: [
1334
+ /* @__PURE__ */ jsx(FormLabel, { children: l.username }),
1335
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { ...field, autoComplete: "off" }) }),
1336
+ /* @__PURE__ */ jsx(FormMessage, {})
1337
+ ] })
1338
+ }
1339
+ ),
1340
+ /* @__PURE__ */ jsx(
1341
+ FormField,
1342
+ {
1343
+ control: form.control,
1344
+ name: "timeout",
1345
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1346
+ /* @__PURE__ */ jsx(FormLabel, { children: l.timeout }),
1347
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { ...portInput(field) }) }),
1348
+ /* @__PURE__ */ jsx(FormMessage, {})
1349
+ ] })
1350
+ }
1351
+ )
1352
+ ] }),
1353
+ /* @__PURE__ */ jsx(
1354
+ FormField,
1355
+ {
1356
+ control: form.control,
1357
+ name: "kind",
1358
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1359
+ /* @__PURE__ */ jsx(FormLabel, { children: l.kind }),
1360
+ /* @__PURE__ */ jsxs(Select, { value: field.value, onValueChange: field.onChange, children: [
1361
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(SelectTrigger, { className: "w-full", children: /* @__PURE__ */ jsx(SelectValue, {}) }) }),
1362
+ /* @__PURE__ */ jsx(SelectContent, { children: kinds.map((k) => /* @__PURE__ */ jsx(SelectItem, { value: k, children: kindLabel[k] }, k)) })
1363
+ ] }),
1364
+ /* @__PURE__ */ jsx(FormMessage, {})
1365
+ ] })
1366
+ }
1367
+ ),
1368
+ kind === "password" && /* @__PURE__ */ jsx(
1369
+ FormField,
1370
+ {
1371
+ control: form.control,
1372
+ name: "password",
1373
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1374
+ /* @__PURE__ */ jsx(FormLabel, { children: l.password }),
1375
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { ...field, value: field.value ?? "", type: "password", placeholder: secretPlaceholder, autoComplete: "new-password" }) }),
1376
+ /* @__PURE__ */ jsx(FormMessage, {})
1377
+ ] })
1378
+ }
1379
+ ),
1380
+ kind === "keypair" && /* @__PURE__ */ jsxs(Fragment, { children: [
1381
+ /* @__PURE__ */ jsx(
1382
+ FormField,
1383
+ {
1384
+ control: form.control,
1385
+ name: "private_key",
1386
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1387
+ /* @__PURE__ */ jsx(FormLabel, { children: l.privateKey }),
1388
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
1389
+ Textarea,
1390
+ {
1391
+ ...field,
1392
+ value: field.value ?? "",
1393
+ className: "min-h-[120px] font-mono text-xs",
1394
+ placeholder: secretPlaceholder ?? l.privateKeyPlaceholder
1395
+ }
1396
+ ) }),
1397
+ /* @__PURE__ */ jsx(FormMessage, {})
1398
+ ] })
1399
+ }
1400
+ ),
1401
+ /* @__PURE__ */ jsx(
1402
+ FormField,
1403
+ {
1404
+ control: form.control,
1405
+ name: "passphrase",
1406
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1407
+ /* @__PURE__ */ jsx(FormLabel, { children: `${l.passphrase} (${l.optional})` }),
1408
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { ...field, value: field.value ?? "", type: "password", placeholder: secretPlaceholder, autoComplete: "new-password" }) }),
1409
+ /* @__PURE__ */ jsx(FormMessage, {})
1410
+ ] })
1411
+ }
1412
+ )
1413
+ ] }),
1414
+ pinHostKey && /* @__PURE__ */ jsx(
1415
+ FormField,
1416
+ {
1417
+ control: form.control,
1418
+ name: "host_key",
1419
+ render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
1420
+ /* @__PURE__ */ jsx(FormLabel, { children: l.hostKey }),
1421
+ /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(Input, { value: field.value || l.hostKeyUntrusted, readOnly: true, className: "font-mono text-xs" }) }),
1422
+ /* @__PURE__ */ jsx(FormDescription, { children: l.hostKeyHint })
1423
+ ] })
1424
+ }
1425
+ )
1426
+ ] });
1427
+ }
1428
+ function usePinFollowsAddress(form, on) {
1429
+ useEffect(() => {
1430
+ if (!on) return;
1431
+ const sub = form.watch((v, { name, type }) => {
1432
+ if (type !== "change" || name !== "host" && name !== "port") return;
1433
+ const origin = form.formState.defaultValues;
1434
+ const same = v.host === origin?.host && v.port === origin?.port;
1435
+ form.setValue("host_key", same ? origin?.host_key ?? "" : "");
1436
+ });
1437
+ return () => sub.unsubscribe();
1438
+ }, [form, on]);
1439
+ }
1440
+
1441
+ // src/blocks/connection/host-key.ts
1442
+ var HOST_KEY_UNKNOWN = "ssh_host_key_unknown";
1443
+ var HOST_KEY_CHANGED = "ssh_host_key_changed";
1444
+ function hostKeyAsk(e) {
1445
+ if (typeof e !== "object" || e === null) return null;
1446
+ const { code, details } = e;
1447
+ if (code !== HOST_KEY_UNKNOWN && code !== HOST_KEY_CHANGED) return null;
1448
+ const d = typeof details === "object" && details !== null ? details : {};
1449
+ if (typeof d.key !== "string" || !d.key) return null;
1450
+ return { key: d.key, fingerprint: typeof d.fingerprint === "string" ? d.fingerprint : "", changed: code === HOST_KEY_CHANGED, details: d };
1451
+ }
1452
+ function sharedWhilePending() {
1453
+ const pending = /* @__PURE__ */ new Map();
1454
+ return (id, run) => {
1455
+ const inFlight = pending.get(id);
1456
+ if (inFlight) return inFlight;
1457
+ const p = run().finally(() => pending.delete(id));
1458
+ pending.set(id, p);
1459
+ return p;
1460
+ };
1461
+ }
1462
+ async function retryAfterTrust(run, confirm, trustFor) {
1463
+ try {
1464
+ return { declined: false, value: await run(), trusted: false };
1465
+ } catch (e) {
1466
+ const ask = hostKeyAsk(e);
1467
+ const pin = ask ? trustFor(ask) : void 0;
1468
+ if (!ask || !pin) throw e;
1469
+ if (!await confirm(ask)) return { declined: true, error: e };
1470
+ await pin();
1471
+ return { declined: false, value: await run(), trusted: true };
1472
+ }
1473
+ }
1474
+ var shared = sharedWhilePending();
1475
+ function useHostKeyTrust(labels) {
1476
+ const confirm = useConfirm();
1477
+ const latest = useRef({ confirm, labels });
1478
+ useEffect(() => {
1479
+ latest.current = { confirm, labels };
1480
+ });
1481
+ const confirmHostKey = useCallback((ask, scope = "") => {
1482
+ return shared(`${scope}|${ask.changed}|${ask.key}`, () => {
1483
+ const { confirm: confirm2, labels: labels2 } = latest.current;
1484
+ return confirm2({
1485
+ title: ask.changed ? labels2.changedTitle : labels2.trustTitle,
1486
+ description: ask.changed ? labels2.changedDescription(ask.fingerprint) : labels2.trustDescription(ask.fingerprint),
1487
+ confirmText: labels2.trust,
1488
+ cancelText: labels2.cancel,
1489
+ danger: ask.changed
1490
+ });
1491
+ });
1492
+ }, []);
1493
+ const runWithTrust = useCallback(
1494
+ (run, trustFor, scope = "") => retryAfterTrust(run, (ask) => confirmHostKey(ask, scope), trustFor),
1495
+ [confirmHostKey]
1496
+ );
1497
+ return { confirmHostKey, runWithTrust };
1498
+ }
725
1499
  var FALLBACK_ZONES = [
726
1500
  "UTC",
727
1501
  "Asia/Ho_Chi_Minh",
@@ -805,8 +1579,8 @@ function TzPicker({
805
1579
  search: labels?.search ?? "Search timezone",
806
1580
  noMatch: labels?.noMatch ?? "No match"
807
1581
  };
808
- const own = React5.useMemo(() => browserTz(), []);
809
- const entries = React5.useMemo(() => {
1582
+ const own = React6.useMemo(() => browserTz(), []);
1583
+ const entries = React6.useMemo(() => {
810
1584
  const zones = allZones();
811
1585
  const out = [];
812
1586
  if (allowInherit) out.push({ tz: "", name: l.inherit, offset: "" });
@@ -853,6 +1627,211 @@ function TzPicker({
853
1627
  }
854
1628
  );
855
1629
  }
1630
+ function MobileSheet({ title, description, trigger, open, onOpenChange, className, children }) {
1631
+ const [inner, setInner] = useState(false);
1632
+ const shown = open ?? inner;
1633
+ const change = (next) => {
1634
+ if (open === void 0) setInner(next);
1635
+ onOpenChange?.(next);
1636
+ };
1637
+ useBackClose(shown, () => change(false));
1638
+ return /* @__PURE__ */ jsxs(Drawer, { open: shown, onOpenChange: change, children: [
1639
+ trigger && /* @__PURE__ */ jsx(DrawerTrigger, { asChild: true, children: trigger }),
1640
+ /* @__PURE__ */ jsxs(DrawerContent, { children: [
1641
+ /* @__PURE__ */ jsxs(DrawerHeader, { children: [
1642
+ /* @__PURE__ */ jsx(DrawerTitle, { className: "text-base", children: title }),
1643
+ description && /* @__PURE__ */ jsx(DrawerDescription, { className: "text-sm", children: description })
1644
+ ] }),
1645
+ /* @__PURE__ */ jsx("div", { className: cn("min-h-0 overflow-y-auto px-4 pb-[calc(1.5rem+env(safe-area-inset-bottom))] text-sm", className), children })
1646
+ ] })
1647
+ ] });
1648
+ }
1649
+ var CALENDAR_LOCALES = { vi, ja, en: enUS };
1650
+ function datePattern(locale) {
1651
+ const parts = new Intl.DateTimeFormat(locale, { day: "2-digit", month: "2-digit", year: "numeric" }).formatToParts(
1652
+ new Date(2001, 10, 22)
1653
+ );
1654
+ const order = [];
1655
+ let sep = "/";
1656
+ for (const p of parts) {
1657
+ if (p.type === "day") order.push("d");
1658
+ else if (p.type === "month") order.push("m");
1659
+ else if (p.type === "year") order.push("y");
1660
+ else if (p.type === "literal" && order.length === 1) sep = p.value.trim() || p.value;
1661
+ }
1662
+ return order.length === 3 ? { order, sep } : { order: ["d", "m", "y"], sep: "/" };
1663
+ }
1664
+ var pad = (n, w) => String(n).padStart(w, "0");
1665
+ function isoOf(y, m, d) {
1666
+ const dt = new Date(Date.UTC(y, m - 1, d));
1667
+ if (dt.getUTCFullYear() !== y || dt.getUTCMonth() !== m - 1 || dt.getUTCDate() !== d) return null;
1668
+ return `${pad(y, 4)}-${pad(m, 2)}-${pad(d, 2)}`;
1669
+ }
1670
+ function formatDate(iso, pattern) {
1671
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso);
1672
+ if (!m) return "";
1673
+ const by = { y: m[1], m: m[2], d: m[3] };
1674
+ return pattern.order.map((p) => by[p]).join(pattern.sep);
1675
+ }
1676
+ function parseDate(text, pattern) {
1677
+ const t = text.trim();
1678
+ if (/^\d{4}-\d{1,2}-\d{1,2}$/.test(t)) {
1679
+ const [y2, mo, d] = t.split("-").map(Number);
1680
+ return isoOf(y2, mo, d);
1681
+ }
1682
+ const nums = t.split(/\D+/).filter(Boolean);
1683
+ if (nums.length !== 3) return null;
1684
+ const by = {};
1685
+ pattern.order.forEach((p, i) => by[p] = Number(nums[i]));
1686
+ let y = by.y;
1687
+ if (nums[pattern.order.indexOf("y")].length <= 2) y += y <= (/* @__PURE__ */ new Date()).getFullYear() % 100 + 10 ? 2e3 : 1900;
1688
+ return isoOf(y, by.m, by.d);
1689
+ }
1690
+ function toDate(iso) {
1691
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso);
1692
+ return m ? new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3])) : void 0;
1693
+ }
1694
+ function fromDate(d) {
1695
+ return `${pad(d.getFullYear(), 4)}-${pad(d.getMonth() + 1, 2)}-${pad(d.getDate(), 2)}`;
1696
+ }
1697
+ function useCoarsePointer() {
1698
+ const [coarse, setCoarse] = React6.useState(false);
1699
+ React6.useEffect(() => {
1700
+ if (typeof window === "undefined" || !window.matchMedia) return;
1701
+ const mql = window.matchMedia("(pointer: coarse)");
1702
+ const onChange = () => setCoarse(mql.matches);
1703
+ onChange();
1704
+ mql.addEventListener("change", onChange);
1705
+ return () => mql.removeEventListener("change", onChange);
1706
+ }, []);
1707
+ return coarse;
1708
+ }
1709
+ function DateField({
1710
+ value,
1711
+ onChange,
1712
+ locale,
1713
+ id,
1714
+ disabled,
1715
+ required,
1716
+ min,
1717
+ max,
1718
+ todayLabel = "Today",
1719
+ clearLabel = "Clear",
1720
+ pickLabel = "Pick a date",
1721
+ className,
1722
+ ...aria
1723
+ }) {
1724
+ const pattern = React6.useMemo(() => datePattern(locale), [locale]);
1725
+ const placeholder = pattern.order.map((p) => p === "y" ? "yyyy" : p === "m" ? "mm" : "dd").join(pattern.sep);
1726
+ const [text, setText] = React6.useState(() => formatDate(value, pattern));
1727
+ const [bad, setBad] = React6.useState(false);
1728
+ const [open, setOpen] = React6.useState(false);
1729
+ const coarse = useCoarsePointer();
1730
+ const [seen, setSeen] = React6.useState(value);
1731
+ if (seen !== value) {
1732
+ setSeen(value);
1733
+ setText(formatDate(value, pattern));
1734
+ setBad(false);
1735
+ }
1736
+ const inRange = (iso) => (!min || iso >= min) && (!max || iso <= max);
1737
+ const commit = () => {
1738
+ if (text.trim() === "") {
1739
+ setBad(false);
1740
+ if (value !== "") onChange("");
1741
+ return;
1742
+ }
1743
+ const iso = parseDate(text, pattern);
1744
+ if (!iso || !inRange(iso)) {
1745
+ setBad(true);
1746
+ setText(formatDate(value, pattern));
1747
+ return;
1748
+ }
1749
+ setBad(false);
1750
+ setText(formatDate(iso, pattern));
1751
+ if (iso !== value) onChange(iso);
1752
+ };
1753
+ const pick = (iso) => {
1754
+ setOpen(false);
1755
+ setBad(false);
1756
+ setText(formatDate(iso, pattern));
1757
+ if (iso !== value) onChange(iso);
1758
+ };
1759
+ const lang = locale.split("-")[0];
1760
+ const calendarLocale = CALENDAR_LOCALES[lang] ?? enUS;
1761
+ const today = fromDate(/* @__PURE__ */ new Date());
1762
+ const selected = toDate(value);
1763
+ const calendar = /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
1764
+ /* @__PURE__ */ jsx(
1765
+ Calendar,
1766
+ {
1767
+ mode: "single",
1768
+ locale: calendarLocale,
1769
+ formatters: { formatWeekdayName: (d) => format(d, lang === "vi" ? "EEEEE" : "EEEEEE", { locale: calendarLocale }) },
1770
+ selected,
1771
+ defaultMonth: selected,
1772
+ captionLayout: "dropdown",
1773
+ disabled: [...min ? [{ before: toDate(min) }] : [], ...max ? [{ after: toDate(max) }] : []],
1774
+ onSelect: (d) => d && pick(fromDate(d))
1775
+ }
1776
+ ),
1777
+ /* @__PURE__ */ jsxs("div", { className: "flex justify-between gap-2 px-2 pb-2", children: [
1778
+ /* @__PURE__ */ jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: () => pick(""), disabled: required, children: clearLabel }),
1779
+ /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", size: "sm", onClick: () => pick(today), disabled: !inRange(today), children: todayLabel })
1780
+ ] })
1781
+ ] });
1782
+ const trigger = /* @__PURE__ */ jsx(InputGroupButton, { type: "button", size: "icon-xs", "aria-label": pickLabel, disabled, children: /* @__PURE__ */ jsx(CalendarIcon, {}) });
1783
+ return /* @__PURE__ */ jsxs(InputGroup, { className, "data-disabled": disabled || void 0, children: [
1784
+ /* @__PURE__ */ jsx(
1785
+ InputGroupInput,
1786
+ {
1787
+ id,
1788
+ inputMode: "numeric",
1789
+ autoComplete: "off",
1790
+ placeholder,
1791
+ value: text,
1792
+ disabled,
1793
+ required,
1794
+ "aria-label": aria["aria-label"],
1795
+ "aria-invalid": bad || aria["aria-invalid"] || void 0,
1796
+ onChange: (e) => {
1797
+ setText(e.target.value);
1798
+ setBad(false);
1799
+ },
1800
+ onBlur: commit,
1801
+ onKeyDown: (e) => {
1802
+ if (e.key === "Enter") {
1803
+ e.preventDefault();
1804
+ commit();
1805
+ }
1806
+ }
1807
+ }
1808
+ ),
1809
+ /* @__PURE__ */ jsx(InputGroupAddon, { align: "inline-end", children: coarse ? /* @__PURE__ */ jsx(MobileSheet, { title: pickLabel, open, onOpenChange: setOpen, trigger, children: /* @__PURE__ */ jsx("div", { className: "flex justify-center", children: calendar }) }) : /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
1810
+ /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: trigger }),
1811
+ /* @__PURE__ */ jsx(PopoverContent, { className: "w-auto p-0", align: "end", children: calendar })
1812
+ ] }) })
1813
+ ] });
1814
+ }
1815
+ function LockedReason({ children, className }) {
1816
+ return /* @__PURE__ */ jsxs("p", { "data-slot": "locked-reason", className: cn("text-muted-foreground flex items-start gap-1 text-xs", className), children: [
1817
+ /* @__PURE__ */ jsx(LockIcon, { "aria-hidden": true, className: "mt-px size-3 shrink-0" }),
1818
+ /* @__PURE__ */ jsx("span", { children })
1819
+ ] });
1820
+ }
1821
+ function UnsavedBadge({ children, className }) {
1822
+ return /* @__PURE__ */ jsxs(
1823
+ "span",
1824
+ {
1825
+ "data-slot": "unsaved-badge",
1826
+ role: "status",
1827
+ className: cn("inline-flex items-center gap-1.5 text-xs font-medium text-amber-700 dark:text-amber-400", className),
1828
+ children: [
1829
+ /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "size-1.5 rounded-full bg-current" }),
1830
+ children
1831
+ ]
1832
+ }
1833
+ );
1834
+ }
856
1835
  var FALLBACK = {
857
1836
  placeholder: "Select\u2026",
858
1837
  search: "Search",
@@ -869,7 +1848,7 @@ function OptionPicker({
869
1848
  }) {
870
1849
  const t = (k) => labels?.[k] ?? FALLBACK[k];
871
1850
  const placeholder = labels?.placeholder ?? FALLBACK.placeholder;
872
- const entries = React5.useMemo(() => {
1851
+ const entries = React6.useMemo(() => {
873
1852
  const out = [{ id: "", label: placeholder, none: true }, ...options];
874
1853
  if (value !== "" && !options.some((o) => o.id === value)) {
875
1854
  out.push({ id: value, label: value });
@@ -921,18 +1900,6 @@ function AuthCard({ title, description, logo, brand, footer, children, className
921
1900
  footer
922
1901
  ] }) });
923
1902
  }
924
- function MobileSheet({ title, description, trigger, open, onOpenChange, className, children }) {
925
- return /* @__PURE__ */ jsxs(Drawer, { open, onOpenChange, children: [
926
- trigger && /* @__PURE__ */ jsx(DrawerTrigger, { asChild: true, children: trigger }),
927
- /* @__PURE__ */ jsxs(DrawerContent, { children: [
928
- /* @__PURE__ */ jsxs(DrawerHeader, { children: [
929
- /* @__PURE__ */ jsx(DrawerTitle, { className: "text-base", children: title }),
930
- description && /* @__PURE__ */ jsx(DrawerDescription, { className: "text-sm", children: description })
931
- ] }),
932
- /* @__PURE__ */ jsx("div", { className: cn("min-h-0 overflow-y-auto px-4 pb-[calc(1.5rem+env(safe-area-inset-bottom))] text-sm", className), children })
933
- ] })
934
- ] });
935
- }
936
1903
  function ChoiceDrawer({ options, value, onValueChange, ...sheet }) {
937
1904
  return /* @__PURE__ */ jsx(MobileSheet, { ...sheet, children: /* @__PURE__ */ jsx(RadioGroup, { value: value ?? "", onValueChange: (v) => onValueChange(v), className: "-mx-4 gap-0 divide-y divide-border", children: options.map((option) => /* @__PURE__ */ jsxs("label", { className: "flex min-h-12 cursor-pointer items-center justify-between gap-4 px-4 py-3 active:bg-muted", children: [
938
1905
  /* @__PURE__ */ jsx("span", { children: option.label }),
@@ -984,21 +1951,21 @@ function McpSettings({
984
1951
  className
985
1952
  }) {
986
1953
  const t = { ...FALLBACK2, ...labels };
987
- const id = React5.useId();
988
- const [status, setStatus] = React5.useState(null);
989
- const [loadError, setLoadError] = React5.useState(null);
990
- const [error, setError] = React5.useState(null);
991
- const [busy, setBusy] = React5.useState(false);
992
- const [copied, setCopied] = React5.useState(false);
993
- const [calls, setCalls] = React5.useState([]);
994
- const changes = React5.useRef(0);
995
- const callKey = React5.useRef(0);
996
- const load = React5.useCallback(() => {
1954
+ const id = React6.useId();
1955
+ const [status, setStatus] = React6.useState(null);
1956
+ const [loadError, setLoadError] = React6.useState(null);
1957
+ const [error, setError] = React6.useState(null);
1958
+ const [busy, setBusy] = React6.useState(false);
1959
+ const [copied, setCopied] = React6.useState(false);
1960
+ const [calls, setCalls] = React6.useState([]);
1961
+ const changes = React6.useRef(0);
1962
+ const callKey = React6.useRef(0);
1963
+ const load = React6.useCallback(() => {
997
1964
  setLoadError(null);
998
1965
  api.status().then(setStatus, (err) => setLoadError(messageOf(err)));
999
1966
  }, [api]);
1000
- React5.useEffect(load, [load]);
1001
- React5.useEffect(() => {
1967
+ React6.useEffect(load, [load]);
1968
+ React6.useEffect(() => {
1002
1969
  if (!api.onCall) return;
1003
1970
  return api.onCall((call) => {
1004
1971
  setCalls((prev) => [{ ...call, key: ++callKey.current, at: /* @__PURE__ */ new Date() }, ...prev].slice(0, RECENT_CALLS));
@@ -1013,7 +1980,7 @@ function McpSettings({
1013
1980
  );
1014
1981
  });
1015
1982
  }, [api]);
1016
- React5.useEffect(() => {
1983
+ React6.useEffect(() => {
1017
1984
  if (!copied) return;
1018
1985
  const timer = setTimeout(() => setCopied(false), 2e3);
1019
1986
  return () => clearTimeout(timer);
@@ -1276,26 +2243,26 @@ function LlmSettings({ api, labels, className, header, footer }) {
1276
2243
  const size = (bytes) => f.size?.(bytes) ?? sizeOf(bytes);
1277
2244
  const nameOf = (pid) => api.providerName?.(pid) ?? pid;
1278
2245
  const slotLabel = (s) => f.slotLabel?.(s) ?? s.label;
1279
- const id = React5.useId();
1280
- const [state, setState] = React5.useState(null);
1281
- const [drivers, setDrivers] = React5.useState([]);
1282
- const [driversError, setDriversError] = React5.useState(null);
1283
- const [found, setFound] = React5.useState([]);
1284
- const [loadError, setLoadError] = React5.useState(null);
1285
- const [error, setError] = React5.useState(null);
1286
- const [busy, setBusy] = React5.useState(false);
1287
- const [draft, setDraft] = React5.useState(null);
1288
- const [draftError, setDraftError] = React5.useState(null);
1289
- const [removing, setRemoving] = React5.useState(null);
1290
- const [models, setModels] = React5.useState({});
1291
- const [typed, setTyped] = React5.useState({});
1292
- const [pulls, setPulls] = React5.useState({});
1293
- const [library, setLibrary] = React5.useState(null);
1294
- const [pullName, setPullName] = React5.useState("");
2246
+ const id = React6.useId();
2247
+ const [state, setState] = React6.useState(null);
2248
+ const [drivers, setDrivers] = React6.useState([]);
2249
+ const [driversError, setDriversError] = React6.useState(null);
2250
+ const [found, setFound] = React6.useState([]);
2251
+ const [loadError, setLoadError] = React6.useState(null);
2252
+ const [error, setError] = React6.useState(null);
2253
+ const [busy, setBusy] = React6.useState(false);
2254
+ const [draft, setDraft] = React6.useState(null);
2255
+ const [draftError, setDraftError] = React6.useState(null);
2256
+ const [removing, setRemoving] = React6.useState(null);
2257
+ const [models, setModels] = React6.useState({});
2258
+ const [typed, setTyped] = React6.useState({});
2259
+ const [pulls, setPulls] = React6.useState({});
2260
+ const [library, setLibrary] = React6.useState(null);
2261
+ const [pullName, setPullName] = React6.useState("");
1295
2262
  const failed = (err) => {
1296
2263
  if (!api.isCanceled?.(err)) setError(messageOf2(err));
1297
2264
  };
1298
- const load = React5.useCallback(() => {
2265
+ const load = React6.useCallback(() => {
1299
2266
  setLoadError(null);
1300
2267
  setDriversError(null);
1301
2268
  api.state().then(setState, (err) => setLoadError(messageOf2(err)));
@@ -1303,8 +2270,8 @@ function LlmSettings({ api, labels, className, header, footer }) {
1303
2270
  api.detect?.().then(setFound, () => {
1304
2271
  });
1305
2272
  }, [api]);
1306
- React5.useEffect(load, [load]);
1307
- React5.useEffect(() => {
2273
+ React6.useEffect(load, [load]);
2274
+ React6.useEffect(() => {
1308
2275
  if (!api.onPull) return;
1309
2276
  return api.onPull(
1310
2277
  (p) => setPulls((prev) => {
@@ -1314,7 +2281,7 @@ function LlmSettings({ api, labels, className, header, footer }) {
1314
2281
  })
1315
2282
  );
1316
2283
  }, [api]);
1317
- const listModels = React5.useCallback(
2284
+ const listModels = React6.useCallback(
1318
2285
  (provider2) => {
1319
2286
  api.models(provider2).then(
1320
2287
  (ms) => setModels((prev) => ({ ...prev, [provider2]: ms })),
@@ -1324,8 +2291,8 @@ function LlmSettings({ api, labels, className, header, footer }) {
1324
2291
  },
1325
2292
  [api]
1326
2293
  );
1327
- const bound = React5.useMemo(() => new Set((state?.slots ?? []).map((s) => s.provider).filter(Boolean)), [state]);
1328
- React5.useEffect(() => {
2294
+ const bound = React6.useMemo(() => new Set((state?.slots ?? []).map((s) => s.provider).filter(Boolean)), [state]);
2295
+ React6.useEffect(() => {
1329
2296
  for (const p of bound) if (!(p in models)) listModels(p);
1330
2297
  }, [bound, models, listModels]);
1331
2298
  const change = async (action) => {
@@ -1818,6 +2785,150 @@ function LlmSettings({ api, labels, className, header, footer }) {
1818
2785
  );
1819
2786
  }
1820
2787
 
1821
- export { AuthCard, AvatarTile, BarList, ChoiceDrawer, ColorSwatches, ConfirmContext, ConfirmDialog, ConfirmProvider, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, LlmSettings, McpSettings, MobileSheet, OptionPicker, Panel, PanelCard, StatTile, TagInput, TreeDndProvider, TreeExpander, TreeIcon, TreeLabel, TreeLines, TreeNode, TreeNodeContent, TreeNodeTrigger, TreeProvider, TreeView, TzPicker, filterTree, flattenTree, loadExpanded, moveId, planDrop, sameOrder, saveExpanded, sortTree, useConfirm, useFormField, useTreeDndNode, useTreeDndRoot };
2788
+ // src/blocks/release-notes-parse.ts
2789
+ var HEADING = /^(#{1,6})\s+(.*?)\s*#*\s*$/;
2790
+ var RULE = /^\s*([-*_])(\s*\1){2,}\s*$/;
2791
+ var FENCE = /^\s*(`{3,}|~{3,})/;
2792
+ var ITEM = /^(\s*)([-*+]|\d+[.)])\s+(.*)$/;
2793
+ var SAFE_HREF = /^(https?:|mailto:)/i;
2794
+ function safeHref(href) {
2795
+ const trimmed = href.trim();
2796
+ return SAFE_HREF.test(trimmed) ? trimmed : null;
2797
+ }
2798
+ function parseReleaseNotes(markdown) {
2799
+ const blocks = [];
2800
+ const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
2801
+ let paragraph = [];
2802
+ let list = null;
2803
+ const flushParagraph = () => {
2804
+ if (paragraph.length) blocks.push({ kind: "paragraph", inline: parseInline(paragraph.join("\n")) });
2805
+ paragraph = [];
2806
+ };
2807
+ const flushList = () => {
2808
+ if (list) blocks.push({ kind: "list", ordered: list.ordered, items: list.items.map((i) => ({ depth: i.depth, inline: parseInline(i.text) })) });
2809
+ list = null;
2810
+ };
2811
+ const flush = () => {
2812
+ flushParagraph();
2813
+ flushList();
2814
+ };
2815
+ for (let i = 0; i < lines.length; i++) {
2816
+ const line = lines[i] ?? "";
2817
+ const fence = FENCE.exec(line);
2818
+ if (fence) {
2819
+ flush();
2820
+ const marker = fence[1] ?? "```";
2821
+ const body = [];
2822
+ for (i++; i < lines.length && !(lines[i] ?? "").trim().startsWith(marker); i++) body.push(lines[i] ?? "");
2823
+ blocks.push({ kind: "code", text: body.join("\n") });
2824
+ continue;
2825
+ }
2826
+ if (!line.trim()) {
2827
+ flush();
2828
+ continue;
2829
+ }
2830
+ const heading = HEADING.exec(line);
2831
+ if (heading) {
2832
+ flush();
2833
+ blocks.push({ kind: "heading", level: heading[1]?.length ?? 1, inline: parseInline(heading[2] ?? "") });
2834
+ continue;
2835
+ }
2836
+ if (RULE.test(line)) {
2837
+ flush();
2838
+ blocks.push({ kind: "rule" });
2839
+ continue;
2840
+ }
2841
+ const item = ITEM.exec(line);
2842
+ if (item) {
2843
+ flushParagraph();
2844
+ const ordered = /\d/.test(item[2] ?? "");
2845
+ if (list && list.ordered !== ordered && (item[1] ?? "").length === 0) flushList();
2846
+ list ??= { ordered, items: [] };
2847
+ list.items.push({ depth: Math.floor((item[1] ?? "").replace(/\t/g, " ").length / 2), text: item[3] ?? "" });
2848
+ continue;
2849
+ }
2850
+ const last = list?.items.at(-1);
2851
+ if (last && /^\s/.test(line)) {
2852
+ last.text += " " + line.trim();
2853
+ continue;
2854
+ }
2855
+ flushList();
2856
+ paragraph.push(line.trim());
2857
+ }
2858
+ flush();
2859
+ return blocks;
2860
+ }
2861
+ var INLINE = /(`+)([\s\S]+?)\1|\*\*([\s\S]+?)\*\*|__([\s\S]+?)__|\*([^*\s][^*]*?)\*|\[([^\]]+)\]\(((?:[^()\s]|\([^()\s]*\))+)(?:\s+"[^"]*")?\)|<(https?:\/\/[^>\s]+)>|(https?:\/\/[^\s<]+[^\s<.,:;!?)\]'"])/g;
2862
+ function parseInline(text) {
2863
+ const out = [];
2864
+ let at = 0;
2865
+ const push = (node) => {
2866
+ const prev = out.at(-1);
2867
+ if (node.kind === "text" && prev?.kind === "text") prev.text += node.text;
2868
+ else out.push(node);
2869
+ };
2870
+ for (const m of text.matchAll(INLINE)) {
2871
+ const start = m.index;
2872
+ if (start > at) push({ kind: "text", text: text.slice(at, start) });
2873
+ at = start + m[0].length;
2874
+ const [whole, , code, strong, strongAlt, em, label, href, angled, bare] = m;
2875
+ if (code !== void 0) push({ kind: "code", text: code.trim() || code });
2876
+ else if (strong !== void 0 || strongAlt !== void 0) push({ kind: "strong", children: parseInline(strong ?? strongAlt ?? "") });
2877
+ else if (em !== void 0) push({ kind: "em", children: parseInline(em) });
2878
+ else if (label !== void 0 && href !== void 0) {
2879
+ const safe = safeHref(href);
2880
+ if (safe) push({ kind: "link", href: safe, children: parseInline(label) });
2881
+ else for (const node of parseInline(label)) push(node);
2882
+ } else if ((angled ?? bare) !== void 0) {
2883
+ const url = angled ?? bare ?? "";
2884
+ push({ kind: "link", href: url, children: [{ kind: "text", text: url }] });
2885
+ } else push({ kind: "text", text: whole });
2886
+ }
2887
+ if (at < text.length) push({ kind: "text", text: text.slice(at) });
2888
+ return out;
2889
+ }
2890
+ function ReleaseNotes({ notes, onOpenLink, className }) {
2891
+ const blocks = parseReleaseNotes(notes);
2892
+ return /* @__PURE__ */ jsx("div", { "data-slot": "release-notes", className: cn("grid gap-1.5 text-sm break-words", className), children: blocks.map((block, i) => /* @__PURE__ */ jsx(Block, { block, onOpenLink }, i)) });
2893
+ }
2894
+ function Block({ block, onOpenLink }) {
2895
+ switch (block.kind) {
2896
+ case "heading":
2897
+ return /* @__PURE__ */ jsx("p", { role: "heading", "aria-level": block.level, className: cn("font-semibold", block.level <= 2 ? "text-sm" : "text-xs", "mt-1 first:mt-0"), children: /* @__PURE__ */ jsx(Inline, { nodes: block.inline, onOpenLink }) });
2898
+ case "paragraph":
2899
+ return /* @__PURE__ */ jsx("p", { className: "whitespace-pre-line", children: /* @__PURE__ */ jsx(Inline, { nodes: block.inline, onOpenLink }) });
2900
+ case "list": {
2901
+ const List = block.ordered ? "ol" : "ul";
2902
+ return /* @__PURE__ */ jsx(List, { className: cn("grid gap-0.5 pl-4", block.ordered ? "list-decimal" : "list-disc"), children: block.items.map((item, i) => /* @__PURE__ */ jsx("li", { style: item.depth ? { marginInlineStart: `${item.depth}rem` } : void 0, children: /* @__PURE__ */ jsx(Inline, { nodes: item.inline, onOpenLink }) }, i)) });
2903
+ }
2904
+ case "code":
2905
+ return /* @__PURE__ */ jsx("pre", { className: "overflow-x-auto rounded-sm bg-muted p-2 font-mono text-xs", children: block.text });
2906
+ case "rule":
2907
+ return /* @__PURE__ */ jsx("hr", { className: "border-border" });
2908
+ }
2909
+ }
2910
+ function Inline({ nodes, onOpenLink }) {
2911
+ return /* @__PURE__ */ jsx(Fragment, { children: nodes.map((node, i) => {
2912
+ switch (node.kind) {
2913
+ case "text":
2914
+ return node.text;
2915
+ case "code":
2916
+ return /* @__PURE__ */ jsx("code", { className: "rounded-sm bg-muted px-1 font-mono text-[0.85em]", children: node.text }, i);
2917
+ case "strong":
2918
+ return /* @__PURE__ */ jsx("strong", { className: "font-semibold", children: /* @__PURE__ */ jsx(Inline, { nodes: node.children, onOpenLink }) }, i);
2919
+ case "em":
2920
+ return /* @__PURE__ */ jsx("em", { children: /* @__PURE__ */ jsx(Inline, { nodes: node.children, onOpenLink }) }, i);
2921
+ case "link": {
2922
+ const open = onOpenLink ? (e) => {
2923
+ e.preventDefault();
2924
+ onOpenLink(node.href);
2925
+ } : void 0;
2926
+ return /* @__PURE__ */ jsx("a", { href: node.href, target: "_blank", rel: "noopener noreferrer", onClick: open, className: "underline underline-offset-2", children: /* @__PURE__ */ jsx(Inline, { nodes: node.children, onOpenLink }) }, i);
2927
+ }
2928
+ }
2929
+ }) });
2930
+ }
2931
+
2932
+ export { AuthCard, AvatarTile, BarList, BlockedContext, BlockedDialog, ChoiceDrawer, ColorSwatches, ConfigListDialog, ConfirmContext, ConfirmDialog, ConfirmProvider, ConfirmReasonContext, ConnectionTree, DateField, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, HOST_KEY_CHANGED, HOST_KEY_UNKNOWN, LlmSettings, LockedReason, McpSettings, MobileSheet, OptionPicker, Panel, PanelCard, ProxyFields, ReleaseNotes, SshFields, StatTile, TagInput, TlsFields, TreeDndProvider, TreeExpander, TreeIcon, TreeLabel, TreeLines, TreeNode, TreeNodeContent, TreeNodeTrigger, TreeProvider, TreeView, TzPicker, UnsavedBadge, buildConnectionTree, connectionNameMatches, datePattern, filterTree, flattenTree, formatDate, hostKeyAsk, loadExpanded, moveId, parseDate, planDrop, proxyDefaults, retryAfterTrust, sameOrder, saveExpanded, sharedWhilePending, sortTree, sshDefaults, tlsDefaults, useBlocked, useConfirm, useConfirmReason, useFormField, useHostKeyTrust, useTreeDndNode, useTreeDndRoot };
1822
2933
  //# sourceMappingURL=index.js.map
1823
2934
  //# sourceMappingURL=index.js.map