react-reason-editor-sidebar 0.1.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.
Files changed (45) hide show
  1. package/dist/Sidebar.d.ts +2 -0
  2. package/dist/SidebarContent.d.ts +7 -0
  3. package/dist/SidebarFooter.d.ts +37 -0
  4. package/dist/SidebarToolbar.d.ts +89 -0
  5. package/dist/SidebarViewMenu.d.ts +20 -0
  6. package/dist/app-types/fileSource.d.ts +124 -0
  7. package/dist/app-types/toc.d.ts +2 -0
  8. package/dist/app-ui/FileTypeIcon.d.ts +11 -0
  9. package/dist/app-ui/alert-dialog.d.ts +14 -0
  10. package/dist/app-ui/badge.d.ts +13 -0
  11. package/dist/app-ui/button.d.ts +15 -0
  12. package/dist/app-ui/context-menu.d.ts +28 -0
  13. package/dist/app-ui/dialog.d.ts +15 -0
  14. package/dist/app-ui/dropdown-menu.d.ts +25 -0
  15. package/dist/app-ui/input.d.ts +7 -0
  16. package/dist/app-ui/sheet.d.ts +13 -0
  17. package/dist/app-ui/tooltip.d.ts +7 -0
  18. package/dist/app-ui/tree.d.ts +23 -0
  19. package/dist/app-utils/file-sources/sources.d.ts +43 -0
  20. package/dist/app-utils/utils.d.ts +1 -0
  21. package/dist/dialogs/FileManagerModal.d.ts +11 -0
  22. package/dist/dialogs/filemanager-data.d.ts +17 -0
  23. package/dist/documents/DocumentTree.d.ts +59 -0
  24. package/dist/documents/defaultDocuments.d.ts +12 -0
  25. package/dist/features/ai-rewrite/AIRewriteSuggestion.d.ts +27 -0
  26. package/dist/features/ai-rewrite/rewriteModes.d.ts +37 -0
  27. package/dist/file-tree/FileTreeContextMenu.d.ts +18 -0
  28. package/dist/file-tree/documentUtils.d.ts +63 -0
  29. package/dist/file-tree/expandLevels.d.ts +32 -0
  30. package/dist/file-tree/filetree.d.ts +66 -0
  31. package/dist/file-tree/index.d.ts +9 -0
  32. package/dist/file-tree/useFileTreeOperations.d.ts +27 -0
  33. package/dist/fileSourceUtils.d.ts +2 -0
  34. package/dist/index.cjs +46 -0
  35. package/dist/index.d.ts +37 -0
  36. package/dist/index.mjs +20301 -0
  37. package/dist/layout/sidebar/index.d.ts +10 -0
  38. package/dist/layout/sidebar/panelOptions.d.ts +37 -0
  39. package/dist/layout/sidebar/types.d.ts +227 -0
  40. package/dist/search/OutlineView.d.ts +51 -0
  41. package/dist/search/relatedDocuments.d.ts +46 -0
  42. package/dist/search/useActiveHeading.d.ts +40 -0
  43. package/dist/style.css +2 -0
  44. package/dist/utils/storage.d.ts +7 -0
  45. package/package.json +77 -0
@@ -0,0 +1,27 @@
1
+ import { RewriteMode } from './rewriteModes';
2
+ /** Props for the {@link AIRewriteSuggestion} component. */
3
+ interface AIRewriteSuggestionProps {
4
+ /** The original selected text before rewriting. */
5
+ originalText: string;
6
+ /** The AI-generated replacement text. */
7
+ suggestedText: string;
8
+ /** Called when the user accepts the suggestion. */
9
+ onApprove: () => void;
10
+ /** Called when the user rejects the suggestion. */
11
+ onReject: () => void;
12
+ /** Optional callback to regenerate with a different rewrite mode. */
13
+ onRegenerate?: (mode: RewriteMode) => void;
14
+ /** Whether to show a spinner instead of the suggestion panel. */
15
+ isLoading?: boolean;
16
+ /** ID of the currently selected rewrite mode, used to highlight the active badge. */
17
+ currentMode?: string;
18
+ }
19
+ /**
20
+ * Renders an AI suggestion card.
21
+ *
22
+ * Shows a spinner while `isLoading` is `true`. Once a suggestion is available
23
+ * it displays the original text (struck-through), the suggested replacement,
24
+ * mode-selection badges, and approve/reject action buttons.
25
+ */
26
+ export declare const AIRewriteSuggestion: ({ originalText, suggestedText, onApprove, onReject, onRegenerate, isLoading, currentMode, }: AIRewriteSuggestionProps) => import("react").JSX.Element;
27
+ export {};
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @module rewriteModes
3
+ * @description Defines and persists the list of AI rewrite modes available
4
+ * in the editor. Modes are stored in `localStorage` so users can customise
5
+ * them without losing changes on refresh.
6
+ */
7
+ /** A single AI rewrite mode configuration. */
8
+ export interface RewriteMode {
9
+ /** Unique identifier used to reference the mode programmatically. */
10
+ id: string;
11
+ /** Human-readable label shown in the UI badges. */
12
+ name: string;
13
+ /** System prompt prepended to the selected text when calling the AI API. */
14
+ prompt: string;
15
+ /** Tailwind colour key used to style the mode badge (e.g. `'blue'`). */
16
+ color?: string;
17
+ }
18
+ /** Built-in rewrite modes shipped with the application. */
19
+ export declare const DEFAULT_REWRITE_MODES: RewriteMode[];
20
+ /**
21
+ * Returns the current list of rewrite modes. Reads from `localStorage` when
22
+ * a saved list exists, otherwise falls back to {@link DEFAULT_REWRITE_MODES}.
23
+ *
24
+ * @returns Array of rewrite mode objects.
25
+ */
26
+ export declare const getRewriteModes: () => RewriteMode[];
27
+ /**
28
+ * Persists a rewrite mode list to `localStorage`.
29
+ *
30
+ * @param modes - The array of modes to store.
31
+ */
32
+ export declare const saveRewriteModes: (modes: RewriteMode[]) => void;
33
+ /**
34
+ * Resets rewrite modes to {@link DEFAULT_REWRITE_MODES} by overwriting the
35
+ * stored list in `localStorage`.
36
+ */
37
+ export declare const resetRewriteModes: () => void;
@@ -0,0 +1,18 @@
1
+ interface FileTreeContextMenuProps {
2
+ children: React.ReactNode;
3
+ itemId: string;
4
+ isFolder: boolean;
5
+ hasCopiedItem: boolean;
6
+ onAddChild?: (itemId: string) => void;
7
+ onAddChildFolder?: (itemId: string) => void;
8
+ onAddSibling?: (itemId: string) => void;
9
+ onAddSiblingFolder?: (itemId: string) => void;
10
+ onRename?: (itemId: string) => void;
11
+ onDuplicate?: (itemId: string) => void;
12
+ onCopy?: (itemId: string) => void;
13
+ onPaste?: (targetId: string | null) => void;
14
+ onDelete?: (itemId: string) => void;
15
+ onManageTags?: (itemId: string) => void;
16
+ }
17
+ export declare const FileTreeContextMenu: ({ children, itemId, isFolder, hasCopiedItem, onAddChild, onAddChildFolder, onAddSibling, onAddSiblingFolder, onRename, onDuplicate, onCopy, onPaste, onDelete, onManageTags, }: FileTreeContextMenuProps) => import("react").JSX.Element;
18
+ export {};
@@ -0,0 +1,63 @@
1
+ /**
2
+ * @module documentUtils
3
+ * @description Utility functions for document tree operations: building
4
+ * flat lists from nested trees, collecting descendant IDs, and resolving
5
+ * drop positions for drag-and-drop reordering.
6
+ */
7
+ import type { Document } from "../documents/DocumentTree";
8
+ /**
9
+ * Utility functions for document tree operations
10
+ */
11
+ /**
12
+ * Generate a unique ID for a new document
13
+ */
14
+ export declare function generateDocumentId(): string;
15
+ /**
16
+ * Find a document by ID in the tree
17
+ */
18
+ export declare function findDocumentById(documents: Document[], id: string): Document | null;
19
+ /**
20
+ * Find the parent document of a given document ID
21
+ */
22
+ export declare function findParentDocument(documents: Document[], id: string): Document | null;
23
+ /**
24
+ * Get all siblings of a document (including itself)
25
+ */
26
+ export declare function getSiblings(documents: Document[], id: string): Document[];
27
+ /**
28
+ * Create a new document with default values
29
+ */
30
+ export declare function createDocument(parentId: string | null, isFolder?: boolean): Document;
31
+ /**
32
+ * Deep clone a document (for duplication)
33
+ * Generates new IDs for the cloned document and all children
34
+ */
35
+ export declare function cloneDocument(doc: Document, newParentId?: string | null): Document;
36
+ /**
37
+ * Flatten a document tree into a flat array
38
+ */
39
+ export declare function flattenDocuments(documents: Document[]): Document[];
40
+ /**
41
+ * Build a tree structure from flat documents array
42
+ */
43
+ export declare function buildDocumentTree(documents: Document[]): Document[];
44
+ /**
45
+ * Update a document in the tree
46
+ */
47
+ export declare function updateDocument(documents: Document[], id: string, updates: Partial<Document>): Document[];
48
+ /**
49
+ * Delete a document from the tree
50
+ */
51
+ export declare function deleteDocument(documents: Document[], id: string): Document[];
52
+ /**
53
+ * Add a document to the tree
54
+ */
55
+ export declare function addDocument(documents: Document[], newDoc: Document, parentId: string | null): Document[];
56
+ /**
57
+ * Move a document to a new position in the tree
58
+ */
59
+ export declare function moveDocument(documents: Document[], draggedId: string, targetId: string | null, position: "before" | "after" | "child"): Document[];
60
+ /**
61
+ * Check if a document is an ancestor of another document
62
+ */
63
+ export declare function isAncestor(documents: Document[], ancestorId: string, descendantId: string): boolean;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @module file-tree/expandLevels
3
+ * @description Pure helpers behind the file tree's "expand one level at a
4
+ * time" cycle: which folders live at each nesting depth, how deep the tree
5
+ * is currently expanded, and which level a click should move to next.
6
+ */
7
+ /** Minimal shape the level math needs from a tree item. */
8
+ export interface FolderLikeItem {
9
+ children?: string[];
10
+ isFolder: boolean;
11
+ }
12
+ export type FolderItems = Record<string, FolderLikeItem>;
13
+ /** Folder ids grouped by nesting depth (index 0 = top-level folders). */
14
+ export declare function getFolderIdsByLevel(items: FolderItems, rootId: string): string[][];
15
+ /** Deepest folder nesting level in the tree (0 = no folders at all). */
16
+ export declare function getMaxFolderLevel(items: FolderItems, rootId: string): number;
17
+ /** Folder ids reachable within `level` levels of nesting (1 = top-level folders). */
18
+ export declare function getFolderIdsUpToLevel(items: FolderItems, rootId: string, level: number): string[];
19
+ /**
20
+ * Infers the deepest folder level that is currently fully expanded: the
21
+ * largest depth `L` such that every folder at depth <= L is expanded.
22
+ * Returns 0 when any top-level folder is collapsed.
23
+ */
24
+ export declare function getExpandedLevel(items: FolderItems, rootId: string, expandedItems: readonly string[]): number;
25
+ /**
26
+ * The level one click of the expand/collapse toggle should move to: one
27
+ * level deeper each time, wrapping back to fully collapsed once the
28
+ * deepest level is showing.
29
+ */
30
+ export declare function nextExpandLevel(currentLevel: number, maxLevel: number): number;
31
+ /** Tooltip text describing what the next click of the toggle will do. */
32
+ export declare function expandToggleLabelFor(currentLevel: number, maxLevel: number): string;
@@ -0,0 +1,66 @@
1
+ import type { Document } from "../documents/DocumentTree";
2
+ export type DocumentTreeHandle = {
3
+ collapseAll: () => void;
4
+ edit: (nodeId: string) => void;
5
+ expandAll: () => void;
6
+ expandToLevel: (level: number) => void;
7
+ /** Deepest folder level currently fully expanded (0 = fully collapsed). */
8
+ getExpandLevel: () => number;
9
+ /** Deepest folder nesting level in the tree (0 = no folders at all). */
10
+ getMaxExpandLevel: () => number;
11
+ };
12
+ interface FileTreeProps {
13
+ activeId: string | null;
14
+ documents: Document[];
15
+ onMove: (draggedId: string, targetId: string | null, position: "before" | "after" | "child") => void;
16
+ onRename?: (id: string, newTitle: string) => void;
17
+ onSelect: (id: string) => void;
18
+ onDelete?: (id: string) => void;
19
+ onDuplicate?: (id: string) => void;
20
+ onAddChild?: (parentId: string) => void;
21
+ onAddChildFolder?: (parentId: string) => void;
22
+ onAddSibling?: (itemId: string) => void;
23
+ onAddSiblingFolder?: (itemId: string) => void;
24
+ onCopy?: (id: string) => void;
25
+ onPaste?: (targetId: string | null) => void;
26
+ onNewFile?: (parentId: string | null) => void;
27
+ onNewFolder?: (parentId: string | null) => void;
28
+ onManageTags?: (id: string) => void;
29
+ /**
30
+ * Reports the tree's live expansion depth so the toolbar's expand/collapse
31
+ * toggle can label its next step. Fires on mount, whenever the expanded
32
+ * depth or the tree's own depth changes, and with zeroes on unmount.
33
+ */
34
+ onExpandStateChange?: (state: {
35
+ level: number;
36
+ maxLevel: number;
37
+ }) => void;
38
+ /**
39
+ * Hands the tree's current expanded-folder set to the host whenever it
40
+ * changes, so the host can persist it. Without this, a stepped
41
+ * expand/collapse lives only in the tree's local state and the next
42
+ * document change (e.g. a rename) resets the tree back to the persisted
43
+ * `isExpanded` flags, throwing the cycle away.
44
+ */
45
+ onExpandedFoldersChange?: (folderIds: string[]) => void;
46
+ }
47
+ type DropPlacement = {
48
+ targetId: string | null;
49
+ position: "before" | "after" | "child";
50
+ };
51
+ /**
52
+ * Turns a headless-tree reorder target into the sibling-relative move the
53
+ * `onMove` callback speaks.
54
+ *
55
+ * `insertionIndex` is the drop slot counted against the parent's children
56
+ * *after* the dragged nodes have been lifted out of them, so the anchor has to
57
+ * be looked up in that same lifted-out list — using the raw `childIndex`
58
+ * against it lands a downward drag one slot too far, which reads as the node
59
+ * refusing to move where it was dropped.
60
+ *
61
+ * Exported for tests.
62
+ */
63
+ export declare function resolveDropPlacement(parentChildren: string[], draggedIds: string[], insertionIndex: number, parentId: string | null): DropPlacement;
64
+ declare const FileTree: import("react").ForwardRefExoticComponent<FileTreeProps & import("react").RefAttributes<DocumentTreeHandle>>;
65
+ export { FileTree };
66
+ export default FileTree;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @module filetree
3
+ * @description File tree components, hooks, and utilities for managing document hierarchy
4
+ */
5
+ export { default as FileTree } from "./filetree";
6
+ export { FileTreeContextMenu } from "./FileTreeContextMenu";
7
+ export { useFileTreeOperations } from "./useFileTreeOperations";
8
+ export * from "./expandLevels";
9
+ export * from "./documentUtils";
@@ -0,0 +1,27 @@
1
+ import type { Document } from "../documents/DocumentTree";
2
+ /**
3
+ * Hook that provides all file tree context menu operations
4
+ * Manages state and handlers for copy/paste, rename, delete, etc.
5
+ */
6
+ export declare function useFileTreeOperations(documents: Document[], onDocumentUpdate: (id: string, updates: Partial<Document>) => void, onDocumentCreate: (parentId: string | null, isFolder: boolean) => void, onDocumentDelete: (id: string) => void, onDocumentDuplicate: (id: string) => void): {
7
+ copiedNodeId: string | null;
8
+ editingNodeId: string | null;
9
+ deleteConfirmId: string | null;
10
+ handleAddChild: (parentId: string) => void;
11
+ handleAddChildFolder: (parentId: string) => void;
12
+ handleAddSibling: (itemId: string) => void;
13
+ handleAddSiblingFolder: (itemId: string) => void;
14
+ handleRename: (id: string, newTitle: string) => void;
15
+ handleStartEdit: (id: string) => void;
16
+ handleCancelEdit: () => void;
17
+ handleDuplicate: (id: string) => void;
18
+ handleCopy: (id: string) => void;
19
+ handlePaste: (_targetId: string | null) => void;
20
+ handleDeleteRequest: (id: string) => void;
21
+ handleDeleteConfirm: () => void;
22
+ handleDeleteCancel: () => void;
23
+ handleManageTags: (id: string) => void;
24
+ findDocument: (id: string) => Document | null;
25
+ findParent: (id: string) => Document | null;
26
+ getSiblings: (id: string) => Document[];
27
+ };
@@ -0,0 +1,2 @@
1
+ export declare const getSourceIcon: (type: string) => import("react").JSX.Element;
2
+ export declare const getSourceTypeLabel: (type: string) => string;