@tradalab/lyra 3.13.0 → 3.14.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.
@@ -89,6 +89,30 @@ declare function ConfirmProvider({ children }: {
89
89
 
90
90
  declare const useConfirm: () => ConfirmFn;
91
91
 
92
+ type TreeData<T> = {
93
+ id: string;
94
+ name: string;
95
+ isGroup?: boolean;
96
+ children?: T[];
97
+ };
98
+ type FlatTreeNode<T> = T & {
99
+ depth: number;
100
+ parentId?: string;
101
+ parentPath: boolean[];
102
+ isExpanded: boolean;
103
+ hasChildren: boolean;
104
+ isLast: boolean;
105
+ };
106
+ /** Groups before leaves at every level, then a natural order by name, or `compare` when given. Returns new arrays. */
107
+ declare function sortTree<T extends TreeData<T>>(items: T[], compare?: (a: T, b: T) => number): T[];
108
+ /** Keeps a node that matches with all its children, and a node whose descendants match with only those. */
109
+ declare function filterTree<T extends TreeData<T>>(items: T[], matches: (item: T) => boolean): T[];
110
+ /** The rows a virtualized list renders: expanded nodes only, with what `TreeNode` needs to draw its lines. */
111
+ declare function flattenTree<T extends TreeData<T>>(items: T[], expandedIds: Set<string>, depth?: number, parentId?: string, parentPath?: boolean[], out?: FlatTreeNode<T>[]): FlatTreeNode<T>[];
112
+ /** `ids` with `id` moved next to `targetId`, for a drag-to-reorder drop. */
113
+ declare function moveId(ids: string[], id: string, targetId: string, pos: "before" | "after"): string[];
114
+ declare const sameOrder: (a: string[], b: string[]) => boolean;
115
+
92
116
  type TreeProviderProps = {
93
117
  children: ReactNode;
94
118
  defaultExpandedIds?: string[];
@@ -487,4 +511,4 @@ declare function LlmSettings({ api, labels, className, }: {
487
511
  className?: string;
488
512
  }): React$1.JSX.Element;
489
513
 
490
- export { AvatarTile, type AvatarTileProps, ChoiceDrawer, type ChoiceDrawerProps, type ChoiceOption, 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, MobileSheet, type MobileSheetProps, OptionPicker, type OptionPickerLabels, Panel, PanelCard, type PanelCardProps, type PanelItemProps, type PickOption, 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, useConfirm, useFormField };
514
+ export { AvatarTile, type AvatarTileProps, ChoiceDrawer, type ChoiceDrawerProps, type ChoiceOption, ConfirmContext, ConfirmDialog, type ConfirmFn, type ConfirmOptions, ConfirmProvider, type FlatTreeNode, 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, MobileSheet, type MobileSheetProps, OptionPicker, type OptionPickerLabels, Panel, PanelCard, type PanelCardProps, type PanelItemProps, type PickOption, type TreeData, 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, filterTree, flattenTree, moveId, sameOrder, sortTree, useConfirm, useFormField };
@@ -169,6 +169,59 @@ var useConfirm = () => {
169
169
  }
170
170
  return ctx;
171
171
  };
172
+
173
+ // src/blocks/tree/data.ts
174
+ var ASCII = /^[ -~]*$/;
175
+ var DIGITS = /\d+/g;
176
+ var naturalKey = (name) => {
177
+ const s = ASCII.test(name) ? name.toLowerCase() : name.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().replace(/đ/g, "d");
178
+ return s.replace(DIGITS, (d) => d.padStart(20, "0"));
179
+ };
180
+ var rank = (item) => item.isGroup ? 0 : 1;
181
+ var cmp = (a, b) => a < b ? -1 : a > b ? 1 : 0;
182
+ function sortTree(items, compare) {
183
+ let sorted;
184
+ if (compare) {
185
+ sorted = [...items].sort((a, b) => rank(a) - rank(b) || compare(a, b));
186
+ } else {
187
+ const keyed = items.map((item) => ({ item, key: naturalKey(item.name) }));
188
+ keyed.sort((a, b) => rank(a.item) - rank(b.item) || cmp(a.key, b.key) || cmp(a.item.name, b.item.name));
189
+ sorted = keyed.map((k) => k.item);
190
+ }
191
+ return sorted.map((item) => item.children?.length ? { ...item, children: sortTree(item.children, compare) } : item);
192
+ }
193
+ function filterTree(items, matches) {
194
+ return items.flatMap((item) => {
195
+ if (matches(item)) return [item];
196
+ const children = item.children ? filterTree(item.children, matches) : [];
197
+ return children.length > 0 ? [{ ...item, children }] : [];
198
+ });
199
+ }
200
+ function flattenTree(items, expandedIds, depth = 0, parentId, parentPath = [], out = []) {
201
+ items.forEach((item, i) => {
202
+ const isLast = i === items.length - 1;
203
+ const hasChildren = !!item.children?.length;
204
+ const isExpanded = expandedIds.has(item.id);
205
+ out.push({
206
+ ...item,
207
+ depth,
208
+ parentId,
209
+ parentPath,
210
+ isExpanded,
211
+ hasChildren,
212
+ isLast
213
+ });
214
+ if (hasChildren && isExpanded) flattenTree(item.children, expandedIds, depth + 1, item.id, [...parentPath, isLast], out);
215
+ });
216
+ return out;
217
+ }
218
+ function moveId(ids, id, targetId, pos) {
219
+ const rest = ids.filter((x) => x !== id);
220
+ const target = rest.indexOf(targetId);
221
+ const at = target < 0 ? rest.length : target + (pos === "after" ? 1 : 0);
222
+ return [...rest.slice(0, at), id, ...rest.slice(at)];
223
+ }
224
+ var sameOrder = (a, b) => a.length === b.length && a.every((id, i) => id === b[i]);
172
225
  var TreeContext = createContext(void 0);
173
226
  var useTree = () => {
174
227
  const context = useContext(TreeContext);
@@ -1313,6 +1366,6 @@ function LlmSettings({
1313
1366
  );
1314
1367
  }
1315
1368
 
1316
- export { AvatarTile, ChoiceDrawer, ConfirmContext, ConfirmDialog, ConfirmProvider, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, LlmSettings, McpSettings, MobileSheet, OptionPicker, Panel, PanelCard, TreeExpander, TreeIcon, TreeLabel, TreeLines, TreeNode, TreeNodeContent, TreeNodeTrigger, TreeProvider, TreeView, TzPicker, useConfirm, useFormField };
1369
+ export { AvatarTile, ChoiceDrawer, ConfirmContext, ConfirmDialog, ConfirmProvider, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, LlmSettings, McpSettings, MobileSheet, OptionPicker, Panel, PanelCard, TreeExpander, TreeIcon, TreeLabel, TreeLines, TreeNode, TreeNodeContent, TreeNodeTrigger, TreeProvider, TreeView, TzPicker, filterTree, flattenTree, moveId, sameOrder, sortTree, useConfirm, useFormField };
1317
1370
  //# sourceMappingURL=index.js.map
1318
1371
  //# sourceMappingURL=index.js.map