@flanksource/clicky-ui 0.3.60 → 0.3.61
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/NOTICE.md +4 -0
- package/dist/chat.cjs +7 -1
- package/dist/chat.js +4 -2
- package/dist/comments/AnnotationSurface.cjs +317 -0
- package/dist/comments/AnnotationSurface.cjs.map +1 -0
- package/dist/comments/AnnotationSurface.d.ts +19 -0
- package/dist/comments/AnnotationSurface.d.ts.map +1 -0
- package/dist/comments/AnnotationSurface.js +317 -0
- package/dist/comments/AnnotationSurface.js.map +1 -0
- package/dist/comments/CapturePin.cjs +26 -0
- package/dist/comments/CapturePin.cjs.map +1 -0
- package/dist/comments/CapturePin.d.ts +12 -0
- package/dist/comments/CapturePin.d.ts.map +1 -0
- package/dist/comments/CapturePin.js +26 -0
- package/dist/comments/CapturePin.js.map +1 -0
- package/dist/comments/CommentAuthor.cjs +17 -3
- package/dist/comments/CommentAuthor.cjs.map +1 -1
- package/dist/comments/CommentAuthor.d.ts +3 -0
- package/dist/comments/CommentAuthor.d.ts.map +1 -1
- package/dist/comments/CommentAuthor.js +18 -5
- package/dist/comments/CommentAuthor.js.map +1 -1
- package/dist/comments/CommentCard.cjs +98 -52
- package/dist/comments/CommentCard.cjs.map +1 -1
- package/dist/comments/CommentCard.d.ts +3 -0
- package/dist/comments/CommentCard.d.ts.map +1 -1
- package/dist/comments/CommentCard.js +100 -54
- package/dist/comments/CommentCard.js.map +1 -1
- package/dist/comments/CommentCardParts.cjs +76 -0
- package/dist/comments/CommentCardParts.cjs.map +1 -1
- package/dist/comments/CommentCardParts.d.ts.map +1 -1
- package/dist/comments/CommentCardParts.js +76 -0
- package/dist/comments/CommentCardParts.js.map +1 -1
- package/dist/comments/CommentComposer.cjs +71 -34
- package/dist/comments/CommentComposer.cjs.map +1 -1
- package/dist/comments/CommentComposer.d.ts +2 -1
- package/dist/comments/CommentComposer.d.ts.map +1 -1
- package/dist/comments/CommentComposer.js +72 -35
- package/dist/comments/CommentComposer.js.map +1 -1
- package/dist/comments/CommentDraftCard.cjs +68 -0
- package/dist/comments/CommentDraftCard.cjs.map +1 -0
- package/dist/comments/CommentDraftCard.d.ts +7 -0
- package/dist/comments/CommentDraftCard.d.ts.map +1 -0
- package/dist/comments/CommentDraftCard.js +68 -0
- package/dist/comments/CommentDraftCard.js.map +1 -0
- package/dist/comments/CommentDraftPopover.cjs +60 -0
- package/dist/comments/CommentDraftPopover.cjs.map +1 -0
- package/dist/comments/CommentDraftPopover.d.ts +6 -0
- package/dist/comments/CommentDraftPopover.d.ts.map +1 -0
- package/dist/comments/CommentDraftPopover.js +60 -0
- package/dist/comments/CommentDraftPopover.js.map +1 -0
- package/dist/comments/CommentEditor.cjs +350 -0
- package/dist/comments/CommentEditor.cjs.map +1 -0
- package/dist/comments/CommentEditor.d.ts +10 -0
- package/dist/comments/CommentEditor.d.ts.map +1 -0
- package/dist/comments/CommentEditor.js +350 -0
- package/dist/comments/CommentEditor.js.map +1 -0
- package/dist/comments/CommentMarkdown.cjs +28 -13
- package/dist/comments/CommentMarkdown.cjs.map +1 -1
- package/dist/comments/CommentMarkdown.d.ts +4 -1
- package/dist/comments/CommentMarkdown.d.ts.map +1 -1
- package/dist/comments/CommentMarkdown.js +28 -13
- package/dist/comments/CommentMarkdown.js.map +1 -1
- package/dist/comments/CommentPersistenceBoundary.cjs +55 -0
- package/dist/comments/CommentPersistenceBoundary.cjs.map +1 -0
- package/dist/comments/CommentPersistenceBoundary.d.ts +6 -0
- package/dist/comments/CommentPersistenceBoundary.d.ts.map +1 -0
- package/dist/comments/CommentPersistenceBoundary.js +55 -0
- package/dist/comments/CommentPersistenceBoundary.js.map +1 -0
- package/dist/comments/CommentPreview.cjs +45 -0
- package/dist/comments/CommentPreview.cjs.map +1 -0
- package/dist/comments/CommentPreview.d.ts +7 -0
- package/dist/comments/CommentPreview.d.ts.map +1 -0
- package/dist/comments/CommentPreview.js +45 -0
- package/dist/comments/CommentPreview.js.map +1 -0
- package/dist/comments/CommentProvider.cjs +34 -9
- package/dist/comments/CommentProvider.cjs.map +1 -1
- package/dist/comments/CommentProvider.d.ts +3 -1
- package/dist/comments/CommentProvider.d.ts.map +1 -1
- package/dist/comments/CommentProvider.js +34 -9
- package/dist/comments/CommentProvider.js.map +1 -1
- package/dist/comments/CommentRail.cjs +83 -0
- package/dist/comments/CommentRail.cjs.map +1 -0
- package/dist/comments/CommentRail.d.ts +18 -0
- package/dist/comments/CommentRail.d.ts.map +1 -0
- package/dist/comments/CommentRail.js +83 -0
- package/dist/comments/CommentRail.js.map +1 -0
- package/dist/comments/CommentReplyInput.cjs +73 -0
- package/dist/comments/CommentReplyInput.cjs.map +1 -0
- package/dist/comments/CommentReplyInput.d.ts +9 -0
- package/dist/comments/CommentReplyInput.d.ts.map +1 -0
- package/dist/comments/CommentReplyInput.js +73 -0
- package/dist/comments/CommentReplyInput.js.map +1 -0
- package/dist/comments/CommentSidePanel.cjs +22 -6
- package/dist/comments/CommentSidePanel.cjs.map +1 -1
- package/dist/comments/CommentSidePanel.d.ts +4 -1
- package/dist/comments/CommentSidePanel.d.ts.map +1 -1
- package/dist/comments/CommentSidePanel.js +22 -6
- package/dist/comments/CommentSidePanel.js.map +1 -1
- package/dist/comments/CommentThread.cjs +4 -1
- package/dist/comments/CommentThread.cjs.map +1 -1
- package/dist/comments/CommentThread.d.ts +3 -2
- package/dist/comments/CommentThread.d.ts.map +1 -1
- package/dist/comments/CommentThread.js +4 -1
- package/dist/comments/CommentThread.js.map +1 -1
- package/dist/comments/CommentThreadList.cjs +55 -86
- package/dist/comments/CommentThreadList.cjs.map +1 -1
- package/dist/comments/CommentThreadList.d.ts +4 -3
- package/dist/comments/CommentThreadList.d.ts.map +1 -1
- package/dist/comments/CommentThreadList.js +56 -87
- package/dist/comments/CommentThreadList.js.map +1 -1
- package/dist/comments/ElementOutline.cjs +20 -0
- package/dist/comments/ElementOutline.cjs.map +1 -0
- package/dist/comments/ElementOutline.d.ts +6 -0
- package/dist/comments/ElementOutline.d.ts.map +1 -0
- package/dist/comments/ElementOutline.js +20 -0
- package/dist/comments/ElementOutline.js.map +1 -0
- package/dist/comments/VocabularyChip.cjs +50 -0
- package/dist/comments/VocabularyChip.cjs.map +1 -0
- package/dist/comments/VocabularyChip.d.ts +6 -0
- package/dist/comments/VocabularyChip.d.ts.map +1 -0
- package/dist/comments/VocabularyChip.js +50 -0
- package/dist/comments/VocabularyChip.js.map +1 -0
- package/dist/comments/VocabularyPreview.cjs +15 -0
- package/dist/comments/VocabularyPreview.cjs.map +1 -0
- package/dist/comments/VocabularyPreview.d.ts +7 -0
- package/dist/comments/VocabularyPreview.d.ts.map +1 -0
- package/dist/comments/VocabularyPreview.js +15 -0
- package/dist/comments/VocabularyPreview.js.map +1 -0
- package/dist/comments/agent-delivery.cjs +23 -0
- package/dist/comments/agent-delivery.cjs.map +1 -0
- package/dist/comments/agent-delivery.d.ts +15 -0
- package/dist/comments/agent-delivery.d.ts.map +1 -0
- package/dist/comments/agent-delivery.js +22 -0
- package/dist/comments/agent-delivery.js.map +1 -0
- package/dist/comments/anchoring/CommentAnchorBridge.cjs +36 -0
- package/dist/comments/anchoring/CommentAnchorBridge.cjs.map +1 -0
- package/dist/comments/anchoring/CommentAnchorBridge.d.ts +8 -0
- package/dist/comments/anchoring/CommentAnchorBridge.d.ts.map +1 -0
- package/dist/comments/anchoring/CommentAnchorBridge.js +36 -0
- package/dist/comments/anchoring/CommentAnchorBridge.js.map +1 -0
- package/dist/comments/anchoring/dom-anchor.cjs +402 -0
- package/dist/comments/anchoring/dom-anchor.cjs.map +1 -0
- package/dist/comments/anchoring/dom-anchor.d.ts +82 -0
- package/dist/comments/anchoring/dom-anchor.d.ts.map +1 -0
- package/dist/comments/anchoring/dom-anchor.js +384 -0
- package/dist/comments/anchoring/dom-anchor.js.map +1 -0
- package/dist/comments/anchoring/index.d.ts +6 -0
- package/dist/comments/anchoring/index.d.ts.map +1 -0
- package/dist/comments/anchoring/markdown-anchor.cjs +188 -0
- package/dist/comments/anchoring/markdown-anchor.cjs.map +1 -0
- package/dist/comments/anchoring/markdown-anchor.d.ts +37 -0
- package/dist/comments/anchoring/markdown-anchor.d.ts.map +1 -0
- package/dist/comments/anchoring/markdown-anchor.js +181 -0
- package/dist/comments/anchoring/markdown-anchor.js.map +1 -0
- package/dist/comments/anchoring/model.cjs +11 -0
- package/dist/comments/anchoring/model.cjs.map +1 -0
- package/dist/comments/anchoring/model.d.ts +30 -0
- package/dist/comments/anchoring/model.d.ts.map +1 -0
- package/dist/comments/anchoring/model.js +8 -0
- package/dist/comments/anchoring/model.js.map +1 -0
- package/dist/comments/anchoring/patch-anchor.cjs +86 -0
- package/dist/comments/anchoring/patch-anchor.cjs.map +1 -0
- package/dist/comments/anchoring/patch-anchor.d.ts +26 -0
- package/dist/comments/anchoring/patch-anchor.d.ts.map +1 -0
- package/dist/comments/anchoring/patch-anchor.js +80 -0
- package/dist/comments/anchoring/patch-anchor.js.map +1 -0
- package/dist/comments/annotation-screenshot.cjs +191 -0
- package/dist/comments/annotation-screenshot.cjs.map +1 -0
- package/dist/comments/annotation-screenshot.d.ts +16 -0
- package/dist/comments/annotation-screenshot.d.ts.map +1 -0
- package/dist/comments/annotation-screenshot.js +189 -0
- package/dist/comments/annotation-screenshot.js.map +1 -0
- package/dist/comments/annotation-types.d.ts +36 -0
- package/dist/comments/annotation-types.d.ts.map +1 -0
- package/dist/comments/comment-context.cjs.map +1 -1
- package/dist/comments/comment-context.d.ts +1 -1
- package/dist/comments/comment-context.d.ts.map +1 -1
- package/dist/comments/comment-context.js.map +1 -1
- package/dist/comments/comment-detail.d.ts +14 -0
- package/dist/comments/comment-detail.d.ts.map +1 -0
- package/dist/comments/comment-persistence.cjs +102 -0
- package/dist/comments/comment-persistence.cjs.map +1 -0
- package/dist/comments/comment-persistence.d.ts +29 -0
- package/dist/comments/comment-persistence.d.ts.map +1 -0
- package/dist/comments/comment-persistence.js +99 -0
- package/dist/comments/comment-persistence.js.map +1 -0
- package/dist/comments/comment-types.cjs.map +1 -1
- package/dist/comments/comment-types.d.ts +18 -0
- package/dist/comments/comment-types.d.ts.map +1 -1
- package/dist/comments/comment-types.js.map +1 -1
- package/dist/comments/comment-utils.cjs +3 -1
- package/dist/comments/comment-utils.cjs.map +1 -1
- package/dist/comments/comment-utils.d.ts.map +1 -1
- package/dist/comments/comment-utils.js +3 -1
- package/dist/comments/comment-utils.js.map +1 -1
- package/dist/comments/comment-vocabulary.cjs +38 -0
- package/dist/comments/comment-vocabulary.cjs.map +1 -0
- package/dist/comments/comment-vocabulary.d.ts +33 -0
- package/dist/comments/comment-vocabulary.d.ts.map +1 -0
- package/dist/comments/comment-vocabulary.js +34 -0
- package/dist/comments/comment-vocabulary.js.map +1 -0
- package/dist/comments/element-picker.cjs +47 -0
- package/dist/comments/element-picker.cjs.map +1 -0
- package/dist/comments/element-picker.d.ts +28 -0
- package/dist/comments/element-picker.d.ts.map +1 -0
- package/dist/comments/element-picker.js +46 -0
- package/dist/comments/element-picker.js.map +1 -0
- package/dist/comments/use-comment-rail-width.cjs +28 -0
- package/dist/comments/use-comment-rail-width.cjs.map +1 -0
- package/dist/comments/use-comment-rail-width.d.ts +2 -0
- package/dist/comments/use-comment-rail-width.d.ts.map +1 -0
- package/dist/comments/use-comment-rail-width.js +28 -0
- package/dist/comments/use-comment-rail-width.js.map +1 -0
- package/dist/comments/vocabulary-capture.cjs +47 -0
- package/dist/comments/vocabulary-capture.cjs.map +1 -0
- package/dist/comments/vocabulary-capture.d.ts +10 -0
- package/dist/comments/vocabulary-capture.d.ts.map +1 -0
- package/dist/comments/vocabulary-capture.js +47 -0
- package/dist/comments/vocabulary-capture.js.map +1 -0
- package/dist/comments.cjs +87 -6
- package/dist/comments.d.ts +18 -1
- package/dist/comments.d.ts.map +1 -1
- package/dist/comments.js +26 -7
- package/dist/components/DateField.d.ts +1 -1
- package/dist/components/DatePicker.d.ts +1 -1
- package/dist/components/DateTimePicker.d.ts +1 -1
- package/dist/components/SplitButton.cjs +2 -2
- package/dist/components/SplitButton.cjs.map +1 -1
- package/dist/components/SplitButton.js +2 -2
- package/dist/components/SplitButton.js.map +1 -1
- package/dist/components/mdx-editor-callout-model.d.ts +1 -1
- package/dist/components/mdx-editor-field-plugins.cjs +11 -2
- package/dist/components/mdx-editor-field-plugins.cjs.map +1 -1
- package/dist/components/mdx-editor-field-plugins.d.ts.map +1 -1
- package/dist/components/mdx-editor-field-plugins.js +11 -2
- package/dist/components/mdx-editor-field-plugins.js.map +1 -1
- package/dist/components/mdx-editor-options.d.ts +7 -0
- package/dist/components/mdx-editor-options.d.ts.map +1 -1
- package/dist/components.cjs +2 -0
- package/dist/components.d.ts +1 -0
- package/dist/components.d.ts.map +1 -1
- package/dist/components.js +2 -1
- package/dist/data/ImagePreview.cjs +42 -0
- package/dist/data/ImagePreview.cjs.map +1 -0
- package/dist/data/ImagePreview.d.ts +13 -0
- package/dist/data/ImagePreview.d.ts.map +1 -0
- package/dist/data/ImagePreview.js +42 -0
- package/dist/data/ImagePreview.js.map +1 -0
- package/dist/data/Markdown.cjs +31 -2
- package/dist/data/Markdown.cjs.map +1 -1
- package/dist/data/Markdown.d.ts +3 -1
- package/dist/data/Markdown.d.ts.map +1 -1
- package/dist/data/Markdown.js +31 -2
- package/dist/data/Markdown.js.map +1 -1
- package/dist/data/MarkdownEditor.model.d.ts +1 -1
- package/dist/data/Tree.cjs +17 -9
- package/dist/data/Tree.cjs.map +1 -1
- package/dist/data/Tree.d.ts +5 -1
- package/dist/data/Tree.d.ts.map +1 -1
- package/dist/data/Tree.js +17 -9
- package/dist/data/Tree.js.map +1 -1
- package/dist/data/TreeNode.cjs +32 -9
- package/dist/data/TreeNode.cjs.map +1 -1
- package/dist/data/TreeNode.d.ts +5 -1
- package/dist/data/TreeNode.d.ts.map +1 -1
- package/dist/data/TreeNode.js +32 -9
- package/dist/data/TreeNode.js.map +1 -1
- package/dist/data/ai/RuntimeModePicker.cjs +1 -1
- package/dist/data/ai/RuntimeModePicker.js +1 -1
- package/dist/data/ai/SessionInspector.summary.cjs +1 -1
- package/dist/data/ai/SessionInspector.summary.js +1 -1
- package/dist/data/ai/SpecRuntimeEditor/ModelSection.cjs +1 -1
- package/dist/data/ai/SpecRuntimeEditor/ModelSection.js +1 -1
- package/dist/data/chat/AgentIdentity.cjs +56 -0
- package/dist/data/chat/AgentIdentity.cjs.map +1 -0
- package/dist/data/chat/AgentIdentity.d.ts +17 -0
- package/dist/data/chat/AgentIdentity.d.ts.map +1 -0
- package/dist/data/chat/AgentIdentity.js +55 -0
- package/dist/data/chat/AgentIdentity.js.map +1 -0
- package/dist/data/chat/Chat.cjs +1 -1
- package/dist/data/chat/Chat.js +1 -1
- package/dist/data/chat/ContextMeter.bar.cjs +2 -2
- package/dist/data/chat/ContextMeter.bar.js +2 -2
- package/dist/data/chat/ContextMeter.model.cjs +41 -13
- package/dist/data/chat/ContextMeter.model.cjs.map +1 -1
- package/dist/data/chat/ContextMeter.model.d.ts +2 -0
- package/dist/data/chat/ContextMeter.model.d.ts.map +1 -1
- package/dist/data/chat/ContextMeter.model.js +41 -14
- package/dist/data/chat/ContextMeter.model.js.map +1 -1
- package/dist/data/chat/ModelSelector.cjs +1 -1
- package/dist/data/chat/ModelSelector.js +1 -1
- package/dist/data/chat/agent-identity-context.cjs +5 -0
- package/dist/data/chat/agent-identity-context.cjs.map +1 -0
- package/dist/data/chat/agent-identity-context.d.ts +7 -0
- package/dist/data/chat/agent-identity-context.d.ts.map +1 -0
- package/dist/data/chat/agent-identity-context.js +6 -0
- package/dist/data/chat/agent-identity-context.js.map +1 -0
- package/dist/data/chat/index.d.ts +3 -0
- package/dist/data/chat/index.d.ts.map +1 -1
- package/dist/data/diagnostics/ActionError.cjs +26 -0
- package/dist/data/diagnostics/ActionError.cjs.map +1 -0
- package/dist/data/diagnostics/ActionError.d.ts +10 -0
- package/dist/data/diagnostics/ActionError.d.ts.map +1 -0
- package/dist/data/diagnostics/ActionError.js +26 -0
- package/dist/data/diagnostics/ActionError.js.map +1 -0
- package/dist/data/diagnostics/error-diagnostics.cjs +7 -0
- package/dist/data/diagnostics/error-diagnostics.cjs.map +1 -1
- package/dist/data/diagnostics/error-diagnostics.d.ts.map +1 -1
- package/dist/data/diagnostics/error-diagnostics.js +7 -0
- package/dist/data/diagnostics/error-diagnostics.js.map +1 -1
- package/dist/data/markdown-urls.cjs +14 -0
- package/dist/data/markdown-urls.cjs.map +1 -0
- package/dist/data/markdown-urls.d.ts +9 -0
- package/dist/data/markdown-urls.d.ts.map +1 -0
- package/dist/data/markdown-urls.js +14 -0
- package/dist/data/markdown-urls.js.map +1 -0
- package/dist/data/runtime/RuntimeBar.model.cjs +1 -1
- package/dist/data/runtime/RuntimeBar.model.js +1 -1
- package/dist/data/version-info.cjs +3 -3
- package/dist/data/version-info.js +3 -3
- package/dist/data.cjs +10 -0
- package/dist/data.d.ts +2 -0
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +5 -1
- package/dist/file-findings/AnnotatedCode.cjs +44 -3
- package/dist/file-findings/AnnotatedCode.cjs.map +1 -1
- package/dist/file-findings/AnnotatedCode.d.ts +7 -0
- package/dist/file-findings/AnnotatedCode.d.ts.map +1 -1
- package/dist/file-findings/AnnotatedCode.js +44 -3
- package/dist/file-findings/AnnotatedCode.js.map +1 -1
- package/dist/file-findings/FileFindingsView.cjs +188 -82
- package/dist/file-findings/FileFindingsView.cjs.map +1 -1
- package/dist/file-findings/FileFindingsView.d.ts +87 -14
- package/dist/file-findings/FileFindingsView.d.ts.map +1 -1
- package/dist/file-findings/FileFindingsView.js +189 -83
- package/dist/file-findings/FileFindingsView.js.map +1 -1
- package/dist/file-findings/FolderFindings.cjs +144 -0
- package/dist/file-findings/FolderFindings.cjs.map +1 -0
- package/dist/file-findings/FolderFindings.d.ts +39 -0
- package/dist/file-findings/FolderFindings.d.ts.map +1 -0
- package/dist/file-findings/FolderFindings.js +144 -0
- package/dist/file-findings/FolderFindings.js.map +1 -0
- package/dist/file-findings/NodeActions.cjs +50 -0
- package/dist/file-findings/NodeActions.cjs.map +1 -0
- package/dist/file-findings/NodeActions.d.ts +15 -0
- package/dist/file-findings/NodeActions.d.ts.map +1 -0
- package/dist/file-findings/NodeActions.js +50 -0
- package/dist/file-findings/NodeActions.js.map +1 -0
- package/dist/file-findings/SeverityCounts.cjs +22 -0
- package/dist/file-findings/SeverityCounts.cjs.map +1 -0
- package/dist/file-findings/SeverityCounts.d.ts +6 -0
- package/dist/file-findings/SeverityCounts.d.ts.map +1 -0
- package/dist/file-findings/SeverityCounts.js +22 -0
- package/dist/file-findings/SeverityCounts.js.map +1 -0
- package/dist/file-findings/adapters.cjs +43 -16
- package/dist/file-findings/adapters.cjs.map +1 -1
- package/dist/file-findings/adapters.d.ts +8 -7
- package/dist/file-findings/adapters.d.ts.map +1 -1
- package/dist/file-findings/adapters.js +43 -16
- package/dist/file-findings/adapters.js.map +1 -1
- package/dist/file-findings/file-review/CommentDraft.cjs +10 -43
- package/dist/file-findings/file-review/CommentDraft.cjs.map +1 -1
- package/dist/file-findings/file-review/CommentDraft.d.ts +4 -2
- package/dist/file-findings/file-review/CommentDraft.d.ts.map +1 -1
- package/dist/file-findings/file-review/CommentDraft.js +11 -44
- package/dist/file-findings/file-review/CommentDraft.js.map +1 -1
- package/dist/file-findings/file-review/EditThreads.cjs +85 -0
- package/dist/file-findings/file-review/EditThreads.cjs.map +1 -0
- package/dist/file-findings/file-review/EditThreads.d.ts +40 -0
- package/dist/file-findings/file-review/EditThreads.d.ts.map +1 -0
- package/dist/file-findings/file-review/EditThreads.js +85 -0
- package/dist/file-findings/file-review/EditThreads.js.map +1 -0
- package/dist/file-findings/file-review/FileReview.cjs +559 -54
- package/dist/file-findings/file-review/FileReview.cjs.map +1 -1
- package/dist/file-findings/file-review/FileReview.d.ts +67 -9
- package/dist/file-findings/file-review/FileReview.d.ts.map +1 -1
- package/dist/file-findings/file-review/FileReview.js +562 -57
- package/dist/file-findings/file-review/FileReview.js.map +1 -1
- package/dist/file-findings/file-review/FileThreads.cjs +96 -0
- package/dist/file-findings/file-review/FileThreads.cjs.map +1 -0
- package/dist/file-findings/file-review/FileThreads.d.ts +50 -0
- package/dist/file-findings/file-review/FileThreads.d.ts.map +1 -0
- package/dist/file-findings/file-review/FileThreads.js +94 -0
- package/dist/file-findings/file-review/FileThreads.js.map +1 -0
- package/dist/file-findings/file-review/InlineThread.cjs +2 -1
- package/dist/file-findings/file-review/InlineThread.cjs.map +1 -1
- package/dist/file-findings/file-review/InlineThread.d.ts +9 -2
- package/dist/file-findings/file-review/InlineThread.d.ts.map +1 -1
- package/dist/file-findings/file-review/InlineThread.js +2 -1
- package/dist/file-findings/file-review/InlineThread.js.map +1 -1
- package/dist/file-findings/file-review/ProblemsList.cjs +67 -56
- package/dist/file-findings/file-review/ProblemsList.cjs.map +1 -1
- package/dist/file-findings/file-review/ProblemsList.d.ts +7 -0
- package/dist/file-findings/file-review/ProblemsList.d.ts.map +1 -1
- package/dist/file-findings/file-review/ProblemsList.js +68 -58
- package/dist/file-findings/file-review/ProblemsList.js.map +1 -1
- package/dist/file-findings/file-review/SourceView.cjs +2 -1
- package/dist/file-findings/file-review/SourceView.cjs.map +1 -1
- package/dist/file-findings/file-review/SourceView.js +3 -2
- package/dist/file-findings/file-review/SourceView.js.map +1 -1
- package/dist/file-findings/file-review/geometry.cjs +36 -7
- package/dist/file-findings/file-review/geometry.cjs.map +1 -1
- package/dist/file-findings/file-review/geometry.d.ts +9 -3
- package/dist/file-findings/file-review/geometry.d.ts.map +1 -1
- package/dist/file-findings/file-review/geometry.js +36 -7
- package/dist/file-findings/file-review/geometry.js.map +1 -1
- package/dist/file-findings/file-review/hooks.cjs +36 -3
- package/dist/file-findings/file-review/hooks.cjs.map +1 -1
- package/dist/file-findings/file-review/hooks.d.ts +15 -1
- package/dist/file-findings/file-review/hooks.d.ts.map +1 -1
- package/dist/file-findings/file-review/hooks.js +37 -5
- package/dist/file-findings/file-review/hooks.js.map +1 -1
- package/dist/file-findings/file-review/patch-comments.cjs +65 -0
- package/dist/file-findings/file-review/patch-comments.cjs.map +1 -0
- package/dist/file-findings/file-review/patch-comments.d.ts +29 -0
- package/dist/file-findings/file-review/patch-comments.d.ts.map +1 -0
- package/dist/file-findings/file-review/patch-comments.js +60 -0
- package/dist/file-findings/file-review/patch-comments.js.map +1 -0
- package/dist/file-findings/file-review/post-actions.cjs +33 -0
- package/dist/file-findings/file-review/post-actions.cjs.map +1 -0
- package/dist/file-findings/file-review/post-actions.d.ts +20 -0
- package/dist/file-findings/file-review/post-actions.d.ts.map +1 -0
- package/dist/file-findings/file-review/post-actions.js +30 -0
- package/dist/file-findings/file-review/post-actions.js.map +1 -0
- package/dist/file-findings/file-review/problem-filters.cjs +6 -0
- package/dist/file-findings/file-review/problem-filters.cjs.map +1 -1
- package/dist/file-findings/file-review/problem-filters.d.ts +2 -0
- package/dist/file-findings/file-review/problem-filters.d.ts.map +1 -1
- package/dist/file-findings/file-review/problem-filters.js +6 -1
- package/dist/file-findings/file-review/problem-filters.js.map +1 -1
- package/dist/file-findings/file-review/selection-lines.cjs +47 -0
- package/dist/file-findings/file-review/selection-lines.cjs.map +1 -0
- package/dist/file-findings/file-review/selection-lines.d.ts +19 -0
- package/dist/file-findings/file-review/selection-lines.d.ts.map +1 -0
- package/dist/file-findings/file-review/selection-lines.js +46 -0
- package/dist/file-findings/file-review/selection-lines.js.map +1 -0
- package/dist/file-findings/file-review/views.cjs +16 -0
- package/dist/file-findings/file-review/views.cjs.map +1 -0
- package/dist/file-findings/file-review/views.d.ts +8 -0
- package/dist/file-findings/file-review/views.d.ts.map +1 -0
- package/dist/file-findings/file-review/views.js +14 -0
- package/dist/file-findings/file-review/views.js.map +1 -0
- package/dist/file-findings/file-urls.cjs +60 -0
- package/dist/file-findings/file-urls.cjs.map +1 -0
- package/dist/file-findings/file-urls.d.ts +20 -0
- package/dist/file-findings/file-urls.d.ts.map +1 -0
- package/dist/file-findings/file-urls.js +57 -0
- package/dist/file-findings/file-urls.js.map +1 -0
- package/dist/file-findings/types.cjs +5 -0
- package/dist/file-findings/types.cjs.map +1 -1
- package/dist/file-findings/types.d.ts +8 -2
- package/dist/file-findings/types.d.ts.map +1 -1
- package/dist/file-findings/types.js +5 -1
- package/dist/file-findings/types.js.map +1 -1
- package/dist/file-findings.cjs +24 -0
- package/dist/file-findings.d.ts +9 -4
- package/dist/file-findings.d.ts.map +1 -1
- package/dist/file-findings.js +8 -3
- package/dist/icons/components/UiChecks.cjs +51 -0
- package/dist/icons/components/UiChecks.cjs.map +1 -0
- package/dist/icons/components/UiChecks.d.ts +15 -0
- package/dist/icons/components/UiChecks.d.ts.map +1 -0
- package/dist/icons/components/UiChecks.js +48 -0
- package/dist/icons/components/UiChecks.js.map +1 -0
- package/dist/icons/components/UiPaperPlaneRight.cjs +51 -0
- package/dist/icons/components/UiPaperPlaneRight.cjs.map +1 -0
- package/dist/icons/components/UiPaperPlaneRight.d.ts +15 -0
- package/dist/icons/components/UiPaperPlaneRight.d.ts.map +1 -0
- package/dist/icons/components/UiPaperPlaneRight.js +48 -0
- package/dist/icons/components/UiPaperPlaneRight.js.map +1 -0
- package/dist/icons/index.d.ts +4 -0
- package/dist/icons/index.d.ts.map +1 -1
- package/dist/icons/registry.cjs +4 -0
- package/dist/icons/registry.cjs.map +1 -1
- package/dist/icons/registry.d.ts.map +1 -1
- package/dist/icons/registry.js +4 -0
- package/dist/icons/registry.js.map +1 -1
- package/dist/icons.cjs +6 -0
- package/dist/icons.js +3 -1
- package/dist/index.cjs +99 -6
- package/dist/index.js +31 -7
- package/dist/layout/ResizeHandle.cjs +58 -0
- package/dist/layout/ResizeHandle.cjs.map +1 -0
- package/dist/layout/ResizeHandle.d.ts +13 -0
- package/dist/layout/ResizeHandle.d.ts.map +1 -0
- package/dist/layout/ResizeHandle.js +58 -0
- package/dist/layout/ResizeHandle.js.map +1 -0
- package/dist/monaco/DocumentEditor.cjs +275 -0
- package/dist/monaco/DocumentEditor.cjs.map +1 -0
- package/dist/monaco/DocumentEditor.d.ts +60 -0
- package/dist/monaco/DocumentEditor.d.ts.map +1 -0
- package/dist/monaco/DocumentEditor.js +273 -0
- package/dist/monaco/DocumentEditor.js.map +1 -0
- package/dist/monaco/document-source.cjs +122 -0
- package/dist/monaco/document-source.cjs.map +1 -0
- package/dist/monaco/document-source.d.ts +19 -0
- package/dist/monaco/document-source.d.ts.map +1 -0
- package/dist/monaco/document-source.js +120 -0
- package/dist/monaco/document-source.js.map +1 -0
- package/dist/monaco/source-comments.cjs +34 -0
- package/dist/monaco/source-comments.cjs.map +1 -0
- package/dist/monaco/source-comments.d.ts +19 -0
- package/dist/monaco/source-comments.d.ts.map +1 -0
- package/dist/monaco/source-comments.js +34 -0
- package/dist/monaco/source-comments.js.map +1 -0
- package/dist/monaco.cjs +6 -0
- package/dist/monaco.d.ts +2 -0
- package/dist/monaco.d.ts.map +1 -1
- package/dist/monaco.js +3 -1
- package/dist/styles.css +1 -1
- package/package.json +6 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.js","names":["_Fragment"],"sources":["../../src/data/Markdown.tsx"],"sourcesContent":["import {\n cloneElement,\n isValidElement,\n useEffect,\n useMemo,\n useState,\n type ComponentType,\n type CSSProperties,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n} from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { ConfirmDialog } from \"../overlay/ConfirmDialog\";\nimport { useRouter } from \"../rpc/router\";\nimport { Callout, type CalloutProps } from \"./Callout\";\nimport { CodeBlock } from \"./CodeBlock\";\nimport { rehypeSourceBlocks, sourceAttributes, type SourceAttributes } from \"./markdown-source-blocks\";\n\nexport type MarkdownProps = {\n /** Markdown source text. */\n text: string;\n /** Classes applied to the rendered markdown wrapper. */\n className?: string;\n /**\n * Render `<CalloutBox …>` authored inline in the markdown as a\n * {@link Callout}.\n *\n * Off by default. It admits exactly one extra tag with exactly the callout's\n * own attributes — no other markup in `text` becomes live — so it is safe to\n * turn on wherever callouts are wanted.\n */\n callouts?: boolean | undefined;\n /**\n * Stamp each top-level block with `data-source-start` / `data-source-end`, the\n * 1-based line range of `text` it renders, so a host can anchor annotations\n * to source lines. The document renders as one static block (no streaming),\n * which keeps the line numbers absolute; Streamdown's default sanitising\n * stays in place. Cannot be combined with `callouts`.\n */\n sourceBlocks?: boolean | undefined;\n};\n\n// Streamdown routes a fenced code block to the `code` override with a `data-block`\n// marker (injected by its default `pre` handler); inline code arrives without it.\ntype MarkdownCodeProps = SourceAttributes & {\n className?: string;\n children?: ReactNode;\n \"data-block\"?: string;\n};\n\n// Every override also receives the source `node`, which is not a DOM attribute —\n// each one drops it rather than spreading it onto the element. `style` carries\n// the per-column alignment GFM puts on table cells. `data-source-*` is the one\n// pair of extra attributes forwarded, so `sourceBlocks` anchors survive.\ntype MarkdownElementProps = SourceAttributes & {\n className?: string;\n children?: ReactNode;\n style?: CSSProperties;\n node?: unknown;\n};\n\ntype MarkdownHeadingTag = \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\ntype MarkdownHeadingProps = HTMLAttributes<HTMLHeadingElement> & { node?: unknown };\n\nconst headingClasses: Record<MarkdownHeadingTag, string> = {\n h1: \"mt-4 mb-2 text-lg font-semibold\",\n h2: \"mt-3 mb-1.5 text-base font-semibold\",\n h3: \"mt-3 mb-1 text-sm font-semibold\",\n h4: \"mt-2 mb-1 text-sm font-semibold\",\n h5: \"mt-2 mb-1 text-sm font-medium\",\n h6: \"mt-2 mb-1 text-sm font-medium\",\n};\n\nfunction MarkdownHeading({\n as: Tag,\n className,\n children,\n node: _node,\n ...props\n}: MarkdownHeadingProps & { as: MarkdownHeadingTag }) {\n return (\n <Tag\n className={cn(headingClasses[Tag], className)}\n data-streamdown={`heading-${Tag.slice(1)}`}\n {...props}\n >\n {children}\n </Tag>\n );\n}\n\ntype StreamdownComponent = ComponentType<{\n children: string;\n className?: string | undefined;\n parseIncompleteMarkdown?: boolean | undefined;\n // \"static\" parses the whole document as one block instead of streaming it in\n // blocks, so hast positions are relative to the document.\n mode?: \"static\" | \"streaming\" | undefined;\n rehypePlugins?: readonly unknown[] | undefined;\n // Tag name -> the attribute names it may carry. Streamdown drops every other\n // raw tag, so this is an allowlist rather than raw-HTML passthrough.\n allowedTags?: Record<string, string[]> | undefined;\n components?: {\n pre?: ComponentType<{ children?: ReactNode; node?: unknown } & SourceAttributes>;\n p?: ComponentType<MarkdownElementProps>;\n blockquote?: ComponentType<MarkdownElementProps>;\n hr?: ComponentType<MarkdownElementProps>;\n h1?: ComponentType<MarkdownHeadingProps>;\n h2?: ComponentType<MarkdownHeadingProps>;\n h3?: ComponentType<MarkdownHeadingProps>;\n h4?: ComponentType<MarkdownHeadingProps>;\n h5?: ComponentType<MarkdownHeadingProps>;\n h6?: ComponentType<MarkdownHeadingProps>;\n a?: ComponentType<MarkdownLinkProps>;\n code?: ComponentType<MarkdownCodeProps>;\n ul?: ComponentType<MarkdownElementProps>;\n ol?: ComponentType<MarkdownElementProps>;\n table?: ComponentType<MarkdownElementProps>;\n thead?: ComponentType<MarkdownElementProps>;\n tbody?: ComponentType<MarkdownElementProps>;\n th?: ComponentType<MarkdownElementProps>;\n td?: ComponentType<MarkdownElementProps>;\n // Streamdown lowercases every tag name, so an authored `<CalloutBox>`\n // arrives here as `calloutbox`.\n calloutbox?: ComponentType<CalloutProps & { node?: unknown }>;\n };\n}>;\n\ntype StreamdownModule = {\n Streamdown: StreamdownComponent;\n /** Streamdown's own raw -> sanitize -> harden rehype chain, in that order. */\n defaultRehypePlugins: Record<string, unknown>;\n};\n\nlet loadPromise: Promise<StreamdownModule | null> | null = null;\n\n// Streamdown is an optional peer dependency (like marked/shiki). It is loaded on\n// demand so the core library does not force it on consumers; while it loads (or\n// if it is absent) we fall back to preformatted text.\nfunction loadStreamdown(): Promise<StreamdownModule | null> {\n if (!loadPromise) {\n loadPromise = import(\"streamdown\")\n .then((m) => ({\n Streamdown: m.Streamdown as unknown as StreamdownComponent,\n defaultRehypePlugins: m.defaultRehypePlugins,\n }))\n .catch((err) => {\n console.warn(\"clicky-ui: streamdown not available; rendering markdown as plain text\", err);\n return null;\n });\n }\n return loadPromise;\n}\n\nfunction nodeText(node: ReactNode): string {\n if (typeof node === \"string\") return node;\n if (typeof node === \"number\") return String(node);\n if (Array.isArray(node)) return node.map(nodeText).join(\"\");\n if (isValidElement(node)) return nodeText((node.props as { children?: ReactNode }).children);\n return \"\";\n}\n\n// Render fenced code blocks with the library's theme-aware CodeBlock instead of\n// Streamdown's built-in block, whose Shiki `<pre>` keeps a light background that\n// clashes with the app theme (a white code body inside the dark block chrome).\n// Inline code keeps Streamdown's default inline styling.\nfunction MarkdownCode({ className, children, ...rest }: MarkdownCodeProps) {\n if (!(\"data-block\" in rest)) {\n return (\n <code className={cn(\"rounded bg-muted px-1.5 py-0.5 font-mono text-sm\", className)}>\n {children}\n </code>\n );\n }\n const language = /language-([\\w-]+)/.exec(className ?? \"\")?.[1];\n const source = nodeText(children).replace(/\\n$/, \"\");\n const block = (\n <CodeBlock\n source={source}\n language={language}\n className=\"not-prose my-4\"\n copyable\n downloadable\n themeToggle\n />\n );\n const anchors = sourceAttributes(rest);\n return Object.keys(anchors).length > 0 ? <div {...anchors}>{block}</div> : block;\n}\n\n// Streamdown's default `pre` unwraps to its `code` child, marking it as a block.\n// The source range is stamped on the `pre`, so it is carried over to that child.\nfunction MarkdownPre({ children, ...props }: { children?: ReactNode; node?: unknown } & SourceAttributes) {\n return isValidElement(children)\n ? cloneElement(children as ReactElement<Record<string, unknown>>, {\n \"data-block\": \"true\",\n ...sourceAttributes(props),\n })\n : children;\n}\n\n// Streamdown indents nested lists with `[li_&]:pl-6`, an arbitrary-variant class\n// that only compiles if the consumer's Tailwind happens to scan streamdown's\n// dist — otherwise every level renders flush left. Own the list styling here so\n// the marker and the indent ship from this library's own source. Markers sit\n// outside the padding so each level steps in cleanly. Task lists drop both: the\n// checkbox is the marker.\nfunction MarkdownList({ className, children, ...props }: MarkdownElementProps) {\n const isTaskList = className?.includes(\"contains-task-list\");\n return (\n <ul\n className={cn(\"whitespace-normal\", isTaskList ? \"list-none pl-0\" : \"list-disc pl-6\", className)}\n {...sourceAttributes(props)}\n >\n {children}\n </ul>\n );\n}\n\nfunction MarkdownOrderedList({ className, children, ...props }: MarkdownElementProps) {\n return (\n <ol className={cn(\"list-decimal whitespace-normal pl-6\", className)} {...sourceAttributes(props)}>\n {children}\n </ol>\n );\n}\n\n// Streamdown wraps tables in a `bg-sidebar` card with its own copy/download/\n// fullscreen chrome — a dark navy box around a light table under this library's\n// tokens — and puts the header shading behind `bg-muted/80`, an opacity-modifier\n// class the consumer's Tailwind never sees. Own the whole table instead, styled\n// like DataTable: a bordered scroll container so wide tables scroll rather than\n// overflow the page.\nfunction MarkdownTable({ className, children, ...props }: MarkdownElementProps) {\n return (\n <div\n className=\"not-prose my-4 max-w-full overflow-x-auto rounded-md border border-border\"\n {...sourceAttributes(props)}\n >\n <table className={cn(\"w-max min-w-full table-auto text-left text-sm\", className)}>\n {children}\n </table>\n </div>\n );\n}\n\nfunction MarkdownTableHead({ className, children }: MarkdownElementProps) {\n return <thead className={cn(\"border-b border-border bg-muted\", className)}>{children}</thead>;\n}\n\nfunction MarkdownTableBody({ className, children }: MarkdownElementProps) {\n return <tbody className={cn(\"divide-y divide-border\", className)}>{children}</tbody>;\n}\n\n// `style` holds the column alignment from the delimiter row, so it must survive.\nfunction MarkdownTableHeaderCell({ className, style, children }: MarkdownElementProps) {\n return (\n <th\n className={cn(\"whitespace-nowrap px-density-3 py-density-2 font-semibold\", className)}\n style={style}\n >\n {children}\n </th>\n );\n}\n\nfunction MarkdownTableCell({ className, style, children }: MarkdownElementProps) {\n return (\n <td className={cn(\"px-density-3 py-density-2 align-top\", className)} style={style}>\n {children}\n </td>\n );\n}\n\ntype MarkdownLinkProps = MarkdownElementProps & { href?: string; title?: string };\n\n// Streamdown renders every link as a button behind an \"Open external link?\"\n// prompt that always opens a new tab, so an in-app link such as `/connections`\n// left the app. Root-relative links route through the host's RouterAdapter and\n// hash links scroll in place; only external links keep the confirm prompt.\nfunction MarkdownLink({ href, title, className, children }: MarkdownLinkProps) {\n const { renderLink } = useRouter();\n const [confirming, setConfirming] = useState(false);\n const linkClass = cn(\"wrap-anywhere font-medium text-primary underline\", className);\n\n if (!href) return <span className={className}>{children}</span>;\n if (href.startsWith(\"#\")) {\n return (\n <a href={href} title={title} className={linkClass}>\n {children}\n </a>\n );\n }\n if (href.startsWith(\"/\") && !href.startsWith(\"//\")) {\n return renderLink({ to: href, className: linkClass, children, ...(title ? { title } : {}) });\n }\n return (\n <>\n <a\n href={href}\n title={title}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className={linkClass}\n onClick={(event) => {\n event.preventDefault();\n setConfirming(true);\n }}\n >\n {children}\n </a>\n <ConfirmDialog\n open={confirming}\n title=\"Open external link?\"\n message={<code className=\"break-all font-mono text-sm\">{href}</code>}\n confirmLabel=\"Open link\"\n onCancel={() => setConfirming(false)}\n onConfirm={() => {\n setConfirming(false);\n window.open(href, \"_blank\", \"noopener,noreferrer\");\n }}\n />\n </>\n );\n}\n\nconst markdownComponents = {\n h1: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h1\" {...props} />,\n h2: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h2\" {...props} />,\n h3: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h3\" {...props} />,\n h4: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h4\" {...props} />,\n h5: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h5\" {...props} />,\n h6: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h6\" {...props} />,\n a: MarkdownLink,\n pre: MarkdownPre,\n code: MarkdownCode,\n ul: MarkdownList,\n ol: MarkdownOrderedList,\n table: MarkdownTable,\n thead: MarkdownTableHead,\n tbody: MarkdownTableBody,\n th: MarkdownTableHeaderCell,\n td: MarkdownTableCell,\n};\n\n// The tag arrives lowercased with every attribute as a string, and carries the\n// source hast node too — listing the props drops that rather than spreading it\n// onto the element.\nfunction MarkdownCallout({ badge, children, className, emphasis, icon, label, source, title, variant }: CalloutProps) {\n return (\n <Callout\n badge={badge}\n className={className}\n emphasis={emphasis}\n icon={icon}\n label={label}\n source={source}\n title={title}\n variant={variant}\n >\n {children}\n </Callout>\n );\n}\n\nconst calloutComponents = { ...markdownComponents, calloutbox: MarkdownCallout };\n\nconst CALLOUT_ALLOWED_TAGS = {\n calloutbox: [\"variant\", \"label\", \"badge\", \"source\", \"icon\", \"emphasis\", \"title\"],\n};\n\n/** Renders markdown with Streamdown, which is purpose-built for streaming LLM\n * output (it gracefully handles incomplete markdown mid-stream). Fenced code\n * blocks render via the library CodeBlock, and lists and tables are styled\n * here rather than by Streamdown. Falls back to preformatted text until\n * Streamdown loads or when it is not installed. */\nexport function Markdown({ text, className, callouts = false, sourceBlocks = false }: MarkdownProps) {\n if (sourceBlocks && callouts) {\n throw new Error(\n \"Markdown: sourceBlocks and callouts cannot be combined; callouts replaces the sanitiser schema that sourceBlocks keeps\",\n );\n }\n const [streamdown, setStreamdown] = useState<StreamdownModule | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n loadStreamdown().then((loaded) => {\n if (!cancelled) setStreamdown(loaded);\n });\n return () => {\n cancelled = true;\n };\n }, []);\n\n // Streamdown's own chain (raw, sanitize, harden) followed by the stamping\n // plugin. Appending, rather than replacing, keeps the document sanitised, and\n // running last lets the attributes survive the sanitiser.\n const sourceRehypePlugins = useMemo(\n () => (streamdown ? [...Object.values(streamdown.defaultRehypePlugins), rehypeSourceBlocks] : undefined),\n [streamdown],\n );\n\n if (!streamdown) {\n return <pre className={cn(\"whitespace-pre-wrap text-sm\", className)}>{text}</pre>;\n }\n const { Streamdown } = streamdown;\n\n return (\n <div className={cn(\"prose prose-sm max-w-none dark:prose-invert\", className)}>\n {sourceBlocks ? (\n <Streamdown mode=\"static\" components={markdownComponents} rehypePlugins={sourceRehypePlugins}>\n {text}\n </Streamdown>\n ) : (\n <Streamdown\n parseIncompleteMarkdown\n components={callouts ? calloutComponents : markdownComponents}\n allowedTags={callouts ? CALLOUT_ALLOWED_TAGS : undefined}\n >\n {text}\n </Streamdown>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAiEA,IAAM,iBAAqD;CACzD,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,SAAS,gBAAgB,EACvB,IAAI,KACJ,WACA,UACA,MAAM,OACN,GAAG,SACiD;CACpD,OACE,oBAAC,KAAD;EACE,WAAW,GAAG,eAAe,MAAM,SAAS;EAC5C,mBAAiB,WAAW,IAAI,MAAM,CAAC;EACvC,GAAI;EAEH;CACE,CAAA;AAET;AA6CA,IAAI,cAAuD;AAK3D,SAAS,iBAAmD;CAC1D,IAAI,CAAC,aACH,cAAc,OAAO,aAAa,CAC/B,MAAM,OAAO;EACZ,YAAY,EAAE;EACd,sBAAsB,EAAE;CAC1B,EAAE,CAAC,CACF,OAAO,QAAQ;EACd,QAAQ,KAAK,yEAAyE,GAAG;EACzF,OAAO;CACT,CAAC;CAEL,OAAO;AACT;AAEA,SAAS,SAAS,MAAyB;CACzC,IAAI,OAAO,SAAS,UAAU,OAAO;CACrC,IAAI,OAAO,SAAS,UAAU,OAAO,OAAO,IAAI;CAChD,IAAI,MAAM,QAAQ,IAAI,GAAG,OAAO,KAAK,IAAI,QAAQ,CAAC,CAAC,KAAK,EAAE;CAC1D,IAAI,eAAe,IAAI,GAAG,OAAO,SAAU,KAAK,MAAmC,QAAQ;CAC3F,OAAO;AACT;AAMA,SAAS,aAAa,EAAE,WAAW,UAAU,GAAG,QAA2B;CACzE,IAAI,EAAE,gBAAgB,OACpB,OACE,oBAAC,QAAD;EAAM,WAAW,GAAG,oDAAoD,SAAS;EAC9E;CACG,CAAA;CAGV,MAAM,WAAW,oBAAoB,KAAK,aAAa,EAAE,CAAC,GAAG;CAC7D,MAAM,SAAS,SAAS,QAAQ,CA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AAO,OAAO,WAAW,oBAAoB,GAAG,kBAAkB,IAAI,KAAA,GAC9F,CAAC,UAAU,CACb;CAEA,IAAI,CAAC,YACH,OAAO,oBAAC,OAAD;EAAK,WAAW,GAAG,+BAA+B,SAAS;EAAI,UAAA;CAAU,CAAA;CAElF,MAAM,EAAE,eAAe;CAEvB,OACE,oBAAC,OAAD;EAAK,WAAW,GAAG,+CAA+C,SAAS;EACxE,UAAA,eACC,oBAAC,YAAD;GAAY,MAAK;GAAS,YAAY;GAAoB,eAAe;GACtE,UAAA;EACS,CAAA,IAEZ,oBAAC,YAAD;GACE,yBAAA;GACA,YAAY,WAAW,oBAAoB;GAC3C,aAAa,WAAW,uBAAuB,KAAA;GAE9C,UAAA;EACS,CAAA;CAEX,CAAA;AAET"}
|
|
1
|
+
{"version":3,"file":"Markdown.js","names":["_Fragment"],"sources":["../../src/data/Markdown.tsx"],"sourcesContent":["import {\n cloneElement,\n isValidElement,\n useEffect,\n useMemo,\n useState,\n type ComponentType,\n type CSSProperties,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n} from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { ConfirmDialog } from \"../overlay/ConfirmDialog\";\nimport { useRouter } from \"../rpc/router\";\nimport { Callout, type CalloutProps } from \"./Callout\";\nimport { CodeBlock } from \"./CodeBlock\";\nimport { rehypeSourceBlocks, sourceAttributes, type SourceAttributes } from \"./markdown-source-blocks\";\nimport { rehypeDocumentUrls } from \"./markdown-urls\";\n\nexport type MarkdownProps = {\n /** Resolve sanitized document links and images relative to a host-owned source location. */\n resolveUrl?: ((url: string, kind: \"link\" | \"image\") => string) | undefined;\n /** Markdown source text. */\n text: string;\n /** Classes applied to the rendered markdown wrapper. */\n className?: string;\n /**\n * Render `<CalloutBox …>` authored inline in the markdown as a\n * {@link Callout}.\n *\n * Off by default. It admits exactly one extra tag with exactly the callout's\n * own attributes — no other markup in `text` becomes live — so it is safe to\n * turn on wherever callouts are wanted.\n */\n callouts?: boolean | undefined;\n /**\n * Stamp each top-level block with `data-source-start` / `data-source-end`, the\n * 1-based line range of `text` it renders, so a host can anchor annotations\n * to source lines. The document renders as one static block (no streaming),\n * which keeps the line numbers absolute; Streamdown's default sanitising\n * stays in place. Cannot be combined with `callouts`.\n */\n sourceBlocks?: boolean | undefined;\n};\n\n// Streamdown routes a fenced code block to the `code` override with a `data-block`\n// marker (injected by its default `pre` handler); inline code arrives without it.\ntype MarkdownCodeProps = SourceAttributes & {\n className?: string;\n children?: ReactNode;\n \"data-block\"?: string;\n};\n\n// Every override also receives the source `node`, which is not a DOM attribute —\n// each one drops it rather than spreading it onto the element. `style` carries\n// the per-column alignment GFM puts on table cells. `data-source-*` is the one\n// pair of extra attributes forwarded, so `sourceBlocks` anchors survive.\ntype MarkdownElementProps = SourceAttributes & {\n className?: string;\n children?: ReactNode;\n style?: CSSProperties;\n node?: unknown;\n};\n\ntype MarkdownHeadingTag = \"h1\" | \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\ntype MarkdownHeadingProps = HTMLAttributes<HTMLHeadingElement> & { node?: unknown };\n\nconst headingClasses: Record<MarkdownHeadingTag, string> = {\n h1: \"mt-4 mb-2 text-lg font-semibold\",\n h2: \"mt-3 mb-1.5 text-base font-semibold\",\n h3: \"mt-3 mb-1 text-sm font-semibold\",\n h4: \"mt-2 mb-1 text-sm font-semibold\",\n h5: \"mt-2 mb-1 text-sm font-medium\",\n h6: \"mt-2 mb-1 text-sm font-medium\",\n};\n\nfunction MarkdownHeading({\n as: Tag,\n className,\n children,\n node: _node,\n ...props\n}: MarkdownHeadingProps & { as: MarkdownHeadingTag }) {\n return (\n <Tag\n className={cn(headingClasses[Tag], className)}\n data-streamdown={`heading-${Tag.slice(1)}`}\n {...props}\n >\n {children}\n </Tag>\n );\n}\n\ntype StreamdownComponent = ComponentType<{\n children: string;\n className?: string | undefined;\n parseIncompleteMarkdown?: boolean | undefined;\n // \"static\" parses the whole document as one block instead of streaming it in\n // blocks, so hast positions are relative to the document.\n mode?: \"static\" | \"streaming\" | undefined;\n rehypePlugins?: readonly unknown[] | undefined;\n // Tag name -> the attribute names it may carry. Streamdown drops every other\n // raw tag, so this is an allowlist rather than raw-HTML passthrough.\n allowedTags?: Record<string, string[]> | undefined;\n components?: {\n pre?: ComponentType<{ children?: ReactNode; node?: unknown } & SourceAttributes>;\n p?: ComponentType<MarkdownElementProps>;\n blockquote?: ComponentType<MarkdownElementProps>;\n hr?: ComponentType<MarkdownElementProps>;\n h1?: ComponentType<MarkdownHeadingProps>;\n h2?: ComponentType<MarkdownHeadingProps>;\n h3?: ComponentType<MarkdownHeadingProps>;\n h4?: ComponentType<MarkdownHeadingProps>;\n h5?: ComponentType<MarkdownHeadingProps>;\n h6?: ComponentType<MarkdownHeadingProps>;\n a?: ComponentType<MarkdownLinkProps>;\n img?: ComponentType<MarkdownImageProps>;\n code?: ComponentType<MarkdownCodeProps>;\n ul?: ComponentType<MarkdownElementProps>;\n ol?: ComponentType<MarkdownElementProps>;\n table?: ComponentType<MarkdownElementProps>;\n thead?: ComponentType<MarkdownElementProps>;\n tbody?: ComponentType<MarkdownElementProps>;\n th?: ComponentType<MarkdownElementProps>;\n td?: ComponentType<MarkdownElementProps>;\n // Streamdown lowercases every tag name, so an authored `<CalloutBox>`\n // arrives here as `calloutbox`.\n calloutbox?: ComponentType<CalloutProps & { node?: unknown }>;\n };\n}>;\n\ntype StreamdownModule = {\n Streamdown: StreamdownComponent;\n /** Streamdown's own raw -> sanitize -> harden rehype chain, in that order. */\n defaultRehypePlugins: Record<string, unknown>;\n};\n\nlet loadPromise: Promise<StreamdownModule | null> | null = null;\n\n// Streamdown is an optional peer dependency (like marked/shiki). It is loaded on\n// demand so the core library does not force it on consumers; while it loads (or\n// if it is absent) we fall back to preformatted text.\nfunction loadStreamdown(): Promise<StreamdownModule | null> {\n if (!loadPromise) {\n loadPromise = import(\"streamdown\")\n .then((m) => ({\n Streamdown: m.Streamdown as unknown as StreamdownComponent,\n defaultRehypePlugins: m.defaultRehypePlugins,\n }))\n .catch((err) => {\n console.warn(\"clicky-ui: streamdown not available; rendering markdown as plain text\", err);\n return null;\n });\n }\n return loadPromise;\n}\n\nfunction nodeText(node: ReactNode): string {\n if (typeof node === \"string\") return node;\n if (typeof node === \"number\") return String(node);\n if (Array.isArray(node)) return node.map(nodeText).join(\"\");\n if (isValidElement(node)) return nodeText((node.props as { children?: ReactNode }).children);\n return \"\";\n}\n\n// Render fenced code blocks with the library's theme-aware CodeBlock instead of\n// Streamdown's built-in block, whose Shiki `<pre>` keeps a light background that\n// clashes with the app theme (a white code body inside the dark block chrome).\n// Inline code keeps Streamdown's default inline styling.\nfunction MarkdownCode({ className, children, ...rest }: MarkdownCodeProps) {\n if (!(\"data-block\" in rest)) {\n return (\n <code className={cn(\"rounded bg-muted px-1.5 py-0.5 font-mono text-sm\", className)}>\n {children}\n </code>\n );\n }\n const language = /language-([\\w-]+)/.exec(className ?? \"\")?.[1];\n const source = nodeText(children).replace(/\\n$/, \"\");\n const block = (\n <CodeBlock\n source={source}\n language={language}\n className=\"not-prose my-4\"\n copyable\n downloadable\n themeToggle\n />\n );\n const anchors = sourceAttributes(rest);\n return Object.keys(anchors).length > 0 ? <div {...anchors}>{block}</div> : block;\n}\n\n// Streamdown's default `pre` unwraps to its `code` child, marking it as a block.\n// The source range is stamped on the `pre`, so it is carried over to that child.\nfunction MarkdownPre({ children, ...props }: { children?: ReactNode; node?: unknown } & SourceAttributes) {\n return isValidElement(children)\n ? cloneElement(children as ReactElement<Record<string, unknown>>, {\n \"data-block\": \"true\",\n ...sourceAttributes(props),\n })\n : children;\n}\n\n// Streamdown indents nested lists with `[li_&]:pl-6`, an arbitrary-variant class\n// that only compiles if the consumer's Tailwind happens to scan streamdown's\n// dist — otherwise every level renders flush left. Own the list styling here so\n// the marker and the indent ship from this library's own source. Markers sit\n// outside the padding so each level steps in cleanly. Task lists drop both: the\n// checkbox is the marker.\nfunction MarkdownList({ className, children, ...props }: MarkdownElementProps) {\n const isTaskList = className?.includes(\"contains-task-list\");\n return (\n <ul\n className={cn(\"whitespace-normal\", isTaskList ? \"list-none pl-0\" : \"list-disc pl-6\", className)}\n {...sourceAttributes(props)}\n >\n {children}\n </ul>\n );\n}\n\nfunction MarkdownOrderedList({ className, children, ...props }: MarkdownElementProps) {\n return (\n <ol className={cn(\"list-decimal whitespace-normal pl-6\", className)} {...sourceAttributes(props)}>\n {children}\n </ol>\n );\n}\n\n// Streamdown wraps tables in a `bg-sidebar` card with its own copy/download/\n// fullscreen chrome — a dark navy box around a light table under this library's\n// tokens — and puts the header shading behind `bg-muted/80`, an opacity-modifier\n// class the consumer's Tailwind never sees. Own the whole table instead, styled\n// like DataTable: a bordered scroll container so wide tables scroll rather than\n// overflow the page.\nfunction MarkdownTable({ className, children, ...props }: MarkdownElementProps) {\n return (\n <div\n className=\"not-prose my-4 max-w-full overflow-x-auto rounded-md border border-border\"\n {...sourceAttributes(props)}\n >\n <table className={cn(\"w-max min-w-full table-auto text-left text-sm\", className)}>\n {children}\n </table>\n </div>\n );\n}\n\nfunction MarkdownTableHead({ className, children }: MarkdownElementProps) {\n return <thead className={cn(\"border-b border-border bg-muted\", className)}>{children}</thead>;\n}\n\nfunction MarkdownTableBody({ className, children }: MarkdownElementProps) {\n return <tbody className={cn(\"divide-y divide-border\", className)}>{children}</tbody>;\n}\n\n// `style` holds the column alignment from the delimiter row, so it must survive.\nfunction MarkdownTableHeaderCell({ className, style, children }: MarkdownElementProps) {\n return (\n <th\n className={cn(\"whitespace-nowrap px-density-3 py-density-2 font-semibold\", className)}\n style={style}\n >\n {children}\n </th>\n );\n}\n\nfunction MarkdownTableCell({ className, style, children }: MarkdownElementProps) {\n return (\n <td className={cn(\"px-density-3 py-density-2 align-top\", className)} style={style}>\n {children}\n </td>\n );\n}\n\ntype MarkdownLinkProps = MarkdownElementProps & { href?: string; title?: string };\ntype MarkdownImageProps = MarkdownElementProps & { src?: string; alt?: string; title?: string };\nfunction MarkdownImage({ src, alt, title, className, ...props }: MarkdownImageProps) {\n return <img src={src} alt={alt ?? \"\"} title={title} className={className} loading=\"lazy\" {...sourceAttributes(props)} />;\n}\n\n// Streamdown renders every link as a button behind an \"Open external link?\"\n// prompt that always opens a new tab, so an in-app link such as `/connections`\n// left the app. Root-relative links route through the host's RouterAdapter and\n// hash links scroll in place; only external links keep the confirm prompt.\nfunction MarkdownLink({ href, title, className, children }: MarkdownLinkProps) {\n const { renderLink } = useRouter();\n const [confirming, setConfirming] = useState(false);\n const linkClass = cn(\"wrap-anywhere font-medium text-primary underline\", className);\n\n if (!href) return <span className={className}>{children}</span>;\n if (href.startsWith(\"#\")) {\n return (\n <a href={href} title={title} className={linkClass}>\n {children}\n </a>\n );\n }\n if (href.startsWith(\"/\") && !href.startsWith(\"//\")) {\n return renderLink({ to: href, className: linkClass, children, ...(title ? { title } : {}) });\n }\n return (\n <>\n <a\n href={href}\n title={title}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n className={linkClass}\n onClick={(event) => {\n event.preventDefault();\n setConfirming(true);\n }}\n >\n {children}\n </a>\n <ConfirmDialog\n open={confirming}\n title=\"Open external link?\"\n message={<code className=\"break-all font-mono text-sm\">{href}</code>}\n confirmLabel=\"Open link\"\n onCancel={() => setConfirming(false)}\n onConfirm={() => {\n setConfirming(false);\n window.open(href, \"_blank\", \"noopener,noreferrer\");\n }}\n />\n </>\n );\n}\n\nconst markdownComponents = {\n h1: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h1\" {...props} />,\n h2: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h2\" {...props} />,\n h3: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h3\" {...props} />,\n h4: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h4\" {...props} />,\n h5: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h5\" {...props} />,\n h6: (props: MarkdownHeadingProps) => <MarkdownHeading as=\"h6\" {...props} />,\n a: MarkdownLink,\n img: MarkdownImage,\n pre: MarkdownPre,\n code: MarkdownCode,\n ul: MarkdownList,\n ol: MarkdownOrderedList,\n table: MarkdownTable,\n thead: MarkdownTableHead,\n tbody: MarkdownTableBody,\n th: MarkdownTableHeaderCell,\n td: MarkdownTableCell,\n};\n\n// The tag arrives lowercased with every attribute as a string, and carries the\n// source hast node too — listing the props drops that rather than spreading it\n// onto the element.\nfunction MarkdownCallout({ badge, children, className, emphasis, icon, label, source, title, variant }: CalloutProps) {\n return (\n <Callout\n badge={badge}\n className={className}\n emphasis={emphasis}\n icon={icon}\n label={label}\n source={source}\n title={title}\n variant={variant}\n >\n {children}\n </Callout>\n );\n}\n\nconst calloutComponents = { ...markdownComponents, calloutbox: MarkdownCallout };\n\nconst CALLOUT_ALLOWED_TAGS = {\n calloutbox: [\"variant\", \"label\", \"badge\", \"source\", \"icon\", \"emphasis\", \"title\"],\n};\n\n/** Renders markdown with Streamdown, which is purpose-built for streaming LLM\n * output (it gracefully handles incomplete markdown mid-stream). Fenced code\n * blocks render via the library CodeBlock, and lists and tables are styled\n * here rather than by Streamdown. Falls back to preformatted text until\n * Streamdown loads or when it is not installed. */\nexport function Markdown({ text, className, callouts = false, sourceBlocks = false, resolveUrl }: MarkdownProps) {\n if (sourceBlocks && callouts) {\n throw new Error(\n \"Markdown: sourceBlocks and callouts cannot be combined; callouts replaces the sanitiser schema that sourceBlocks keeps\",\n );\n }\n if (resolveUrl && callouts) throw new Error(\"Markdown: resolveUrl and callouts cannot be combined because callouts owns the sanitizer chain\");\n const [streamdown, setStreamdown] = useState<StreamdownModule | null>(null);\n\n useEffect(() => {\n let cancelled = false;\n loadStreamdown().then((loaded) => {\n if (!cancelled) setStreamdown(loaded);\n });\n return () => {\n cancelled = true;\n };\n }, []);\n\n // Streamdown's own chain (raw, sanitize, harden) followed by the stamping\n // plugin. Appending, rather than replacing, keeps the document sanitised, and\n // running last lets the attributes survive the sanitiser.\n const sourceRehypePlugins = useMemo(() => {\n if (!streamdown) return undefined;\n const { raw, sanitize, harden } = streamdown.defaultRehypePlugins;\n if (!raw || !sanitize || !harden) throw new Error(\"Streamdown must provide its raw, sanitize and harden plugins\");\n return [raw, sanitize, ...(resolveUrl ? [rehypeDocumentUrls(resolveUrl)] : []), harden, ...(sourceBlocks ? [rehypeSourceBlocks] : [])];\n }, [streamdown, sourceBlocks, resolveUrl]);\n\n if (!streamdown) {\n return <pre className={cn(\"whitespace-pre-wrap text-sm\", className)}>{text}</pre>;\n }\n const { Streamdown } = streamdown;\n\n return (\n <div className={cn(\"prose prose-sm max-w-none dark:prose-invert\", className)}>\n {sourceBlocks ? (\n <Streamdown mode=\"static\" components={markdownComponents} rehypePlugins={sourceRehypePlugins}>\n {text}\n </Streamdown>\n ) : (\n <Streamdown\n parseIncompleteMarkdown\n components={callouts ? calloutComponents : markdownComponents}\n {...(resolveUrl ? { rehypePlugins: sourceRehypePlugins } : {})}\n allowedTags={callouts ? CALLOUT_ALLOWED_TAGS : undefined}\n >\n {text}\n </Streamdown>\n )}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAoEA,IAAM,iBAAqD;CACzD,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AAEA,SAAS,gBAAgB,EACvB,IAAI,KACJ,WACA,UACA,MAAM,OACN,GAAG,SACiD;CACpD,OACE,oBAAC,KAAD;EACE,WAAW,GAAG,eAAe,MAAM,SAAS;EAC5C,mBAAiB,WAAW,IAAI,MAAM,CAAC;EACvC,GAAI;EAEH;CACE,CAAA;AAET;AA8CA,IAAI,cAAuD;AAK3D,SAAS,iBAAmD;CAC1D,IAAI,CAAC,aACH,cAAc,OAAO,aAAa,CAC/B,MAAM,OAAO;EACZ,YAAY,EAAE;EACd,sBAAsB,EAAE;CAC1B,EAAE,CAAC,CACF,OAAO,QAAQ;EACd,QAAQ,KAAK,yEAAyE,GAAG;EACzF,OAAO;CACT,CAAC;CAEL,OAAO;AACT;AAEA,SAAS,SAAS,MAAyB;CACzC,IAAI,OAAO,S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AAA,eACC,oBAAC,YAAD;GAAY,MAAK;GAAS,YAAY;GAAoB,eAAe;GACtE,UAAA;EACS,CAAA,IAEZ,oBAAC,YAAD;GACE,yBAAA;GACA,YAAY,WAAW,oBAAoB;GAC3C,GAAK,aAAa,EAAE,eAAe,oBAAoB,IAAI,CAAC;GAC5D,aAAa,WAAW,uBAAuB,KAAA;GAE9C,UAAA;EACS,CAAA;CAEX,CAAA;AAET"}
|
|
@@ -34,5 +34,5 @@ export type MarkdownEditorPreviewHeaders = HeadersInit | ((request: {
|
|
|
34
34
|
format: MarkdownEditorPreviewFormat;
|
|
35
35
|
}) => HeadersInit | undefined);
|
|
36
36
|
export declare function buildMarkdownPreviewUrl(endpoint: string, format: MarkdownEditorPreviewFormat): string;
|
|
37
|
-
export declare function clickyFormatForMarkdownPreview(format: MarkdownEditorPreviewFormat): "
|
|
37
|
+
export declare function clickyFormatForMarkdownPreview(format: MarkdownEditorPreviewFormat): "markdown" | "html" | "json" | "pdf" | "csv" | "excel" | "clicky-json";
|
|
38
38
|
//# sourceMappingURL=MarkdownEditor.model.d.ts.map
|
package/dist/data/Tree.cjs
CHANGED
|
@@ -110,7 +110,7 @@ function filterTreeRoots(roots, getChildren, getKey, query, isSecondary, getSear
|
|
|
110
110
|
forcedOpenKeys
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
function Tree({ roots, empty, className, ariaLabel, showControls = true, showSearch
|
|
113
|
+
function Tree({ roots, empty, className, ariaLabel, showControls = true, showSearch, searchLabel, searchQuery, onSearchQueryChange, expandAll: controlledExpandAll, onExpandAllChange, toolbarClassName, actions, getSearchText, revealSelected = false, ...nodeProps }) {
|
|
114
114
|
const [internalExpandAll, setInternalExpandAll] = (0, react.useState)(null);
|
|
115
115
|
const [internalFilterQuery, setInternalFilterQuery] = (0, react.useState)("");
|
|
116
116
|
const filterQuery = searchQuery ?? internalFilterQuery;
|
|
@@ -127,17 +127,25 @@ function Tree({ roots, empty, className, ariaLabel, showControls = true, showSea
|
|
|
127
127
|
revealKey: selectedKey,
|
|
128
128
|
clickedKey: null
|
|
129
129
|
});
|
|
130
|
-
if (reveal.selectedKey !== selectedKey) setReveal({
|
|
131
|
-
selectedKey,
|
|
132
|
-
revealKey: selectedKey !== null && selectedKey === reveal.clickedKey ? reveal.revealKey : selectedKey,
|
|
133
|
-
clickedKey: null
|
|
134
|
-
});
|
|
135
|
-
const revealKey = reveal.revealKey;
|
|
136
130
|
const [revealInteraction, setRevealInteraction] = (0, react.useState)({
|
|
137
131
|
selectedKey: null,
|
|
138
132
|
overrides: /* @__PURE__ */ new Map(),
|
|
139
133
|
bulk: false
|
|
140
134
|
});
|
|
135
|
+
if (reveal.selectedKey !== selectedKey) {
|
|
136
|
+
const fromTree = selectedKey !== null && selectedKey === reveal.clickedKey;
|
|
137
|
+
setReveal({
|
|
138
|
+
selectedKey,
|
|
139
|
+
revealKey: fromTree ? reveal.revealKey : selectedKey,
|
|
140
|
+
clickedKey: null
|
|
141
|
+
});
|
|
142
|
+
if (!fromTree) setRevealInteraction({
|
|
143
|
+
selectedKey: null,
|
|
144
|
+
overrides: /* @__PURE__ */ new Map(),
|
|
145
|
+
bulk: false
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const revealKey = reveal.revealKey;
|
|
141
149
|
const previousExpandAll = (0, react.useRef)(expandAll);
|
|
142
150
|
(0, react.useEffect)(() => {
|
|
143
151
|
if (previousExpandAll.current === expandAll) return;
|
|
@@ -149,8 +157,8 @@ function Tree({ roots, empty, className, ariaLabel, showControls = true, showSea
|
|
|
149
157
|
});
|
|
150
158
|
}, [expandAll, revealKey]);
|
|
151
159
|
const totalEdges = (0, react.useMemo)(() => countTreeEdges(roots, nodeProps.getChildren), [roots, nodeProps.getChildren]);
|
|
152
|
-
const showFilter = showSearch
|
|
153
|
-
const activeFilter = showFilter ? filterQuery : "";
|
|
160
|
+
const showFilter = showSearch ?? (totalEdges > 20 || Boolean(searchQuery));
|
|
161
|
+
const activeFilter = showFilter || showSearch === false ? filterQuery : "";
|
|
154
162
|
const filteredTree = (0, react.useMemo)(() => filterTreeRoots(roots, nodeProps.getChildren, nodeProps.getKey, activeFilter, nodeProps.isSecondary, getSearchText), [
|
|
155
163
|
roots,
|
|
156
164
|
nodeProps.getChildren,
|
package/dist/data/Tree.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.cjs","names":["useState","useRef","useMemo","_Fragment","cn","Icon","UiSearch","UiClose","UiExpandAll","UiCollapseAll","TreeNode"],"sources":["../../src/data/Tree.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, useState, type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { Icon } from \"./Icon\";\nimport { UiClose, UiCollapseAll, UiExpandAll, UiSearch } from \"../icons\";\nimport { TreeNode, type TreeKey, type TreeNodeProps } from \"./TreeNode\";\n\nexport type TreeProps<T> = Omit<\n TreeNodeProps<T>,\n \"node\" | \"depth\" | \"expandAll\" | \"forcedOpenKeys\" | \"revealPath\" | \"revealOverrides\" | \"onRevealToggle\"\n> & {\n /** Root nodes to render. */\n roots: T[];\n /** Empty-state content when no roots are provided. */\n empty?: ReactNode;\n /** Classes applied to the tree root. */\n className?: string;\n /** Accessible name applied to the tree root. */\n ariaLabel?: string;\n /**\n * Render the Expand all / Collapse all toolbar above the tree. Enabled by\n * default. Set to false to suppress when the tree is tiny or the controls\n * are owned externally.\n */\n showControls?: boolean;\n /** Keep search visible for small or empty trees. */\n showSearch?: boolean;\n /** Placeholder and accessible name of the search box, e.g. \"Filter tests\". */\n searchLabel?: string;\n /** URL or parent-controlled search query. */\n searchQuery?: string;\n onSearchQueryChange?: (query: string) => void;\n /**\n * Externally controlled expand-all state. When provided together with\n * `onExpandAllChange`, the tree is controlled; otherwise it manages the\n * toolbar state internally.\n */\n expandAll?: boolean | null;\n /** Called when the toolbar expand-all state changes. */\n onExpandAllChange?: (next: boolean | null) => void;\n /** Classes applied to the search/control toolbar. */\n toolbarClassName?: string;\n /**\n * Extra controls rendered in the toolbar's right-hand group, before Expand\n * all / Collapse all. Providing actions shows the toolbar even when the tree\n * is too small for the filter and `showControls` is off.\n */\n actions?: ReactNode;\n /**\n * Override the text the filter matches against for a given node.\n * Defaults to a recursive walk of the node's own fields (excluding\n * its `children` and any secondary children), which works for\n * plain-shape trees but leaks text from nested domain objects —\n * e.g. a SQL Table's Field rows are marked secondary, yet the\n * parent record still carries `record.fields[].field` strings that\n * the default walker would collect. Callers that need precise\n * control over search behaviour should return only the text they\n * want surfaced (the node's own display label / id / type).\n */\n getSearchText?: (node: T) => string;\n /**\n * Reveal only the path to `selected` when it changes from outside the tree\n * (initial mount or navigation). Ancestors initially show the next path node;\n * manual expansion and collapse then take precedence until the next external\n * selection. Selecting a row by clicking it never re-reveals. Off by default.\n */\n revealSelected?: boolean;\n};\n\nfunction selectionPath<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n targetKey: TreeKey,\n): Map<TreeKey, TreeKey | null> | null {\n const path = new Map<TreeKey, TreeKey | null>();\n const visit = (node: T): boolean => {\n if (getKey(node) === targetKey) {\n path.set(targetKey, null);\n return true;\n }\n for (const child of getChildren(node) ?? []) {\n if (visit(child)) {\n path.set(getKey(node), getKey(child));\n return true;\n }\n }\n return false;\n };\n for (const root of roots) {\n if (visit(root)) return path;\n }\n return null;\n}\n\n// Edge counting, search-text collection and filtering all walk the tree through\n// the synchronous `getChildren` only. A lazy node (one declared via\n// `hasMoreChildren` whose children have not been fetched yet) therefore\n// contributes no edges and no search text until the operator expands it — so it\n// is invisible to \"expand all\" and to the filter while still collapsed. This is\n// intentional: we never trigger network loads from bulk/search operations.\nfunction countTreeEdges<T>(roots: T[], getChildren: TreeProps<T>[\"getChildren\"]) {\n let total = 0;\n const stack = [...roots];\n\n while (stack.length > 0) {\n const node = stack.pop()!;\n const children = getChildren(node) ?? [];\n total += children.length;\n stack.push(...children);\n }\n\n return total;\n}\n\nfunction collectTreeSearchText(\n value: unknown,\n excluded = new Set<unknown>(),\n seen = new Set<unknown>(),\n): string {\n if (value == null || excluded.has(value)) return \"\";\n\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\"\n ) {\n return String(value);\n }\n\n if (typeof value !== \"object\") return \"\";\n if (seen.has(value)) return \"\";\n seen.add(value);\n\n if (Array.isArray(value)) {\n return value\n .map((entry) => collectTreeSearchText(entry, excluded, seen))\n .filter(Boolean)\n .join(\" \");\n }\n\n const preferredKeys = [\"label\", \"name\", \"title\", \"text\", \"plain\", \"id\", \"content\"];\n const record = value as Record<string, unknown>;\n const chunks: string[] = [];\n\n for (const key of preferredKeys) {\n if (!(key in record)) continue;\n const text = collectTreeSearchText(record[key], excluded, seen);\n if (text) chunks.push(text);\n }\n\n for (const [key, entry] of Object.entries(record)) {\n if (key === \"children\" || preferredKeys.includes(key)) continue;\n const text = collectTreeSearchText(entry, excluded, seen);\n if (text) chunks.push(text);\n }\n\n return chunks.join(\" \");\n}\n\nfunction nodeSearchText<T>(node: T, children: ReturnType<TreeProps<T>[\"getChildren\"]>) {\n const excluded = new Set<unknown>();\n if (children) excluded.add(children);\n return collectTreeSearchText(node, excluded).trim().toLowerCase();\n}\n\nfunction filterTreeRoots<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n query: string,\n isSecondary?: (node: T) => boolean,\n getSearchText?: (node: T) => string,\n) {\n const normalizedQuery = query.trim().toLowerCase();\n if (!normalizedQuery) {\n return {\n roots,\n filteredChildren: null as Map<string | number, T[]> | null,\n forcedOpenKeys: null as Set<string | number> | null,\n };\n }\n\n const filteredChildren = new Map<string | number, T[]>();\n const forcedOpenKeys = new Set<string | number>();\n\n function matchText(node: T, children: T[]): string {\n // Honour the caller-supplied text extractor first — it's the\n // only way to get precise control over what the filter sees when\n // the node carries domain data whose fields would otherwise leak\n // into the default walker.\n if (getSearchText) return getSearchText(node).trim().toLowerCase();\n // Match-text skips secondary children so e.g. a Table's search\n // text only draws from the Table itself, not from its Field\n // rows. The Table is primary, so its own text still counts.\n const searchChildren = children.filter((c) => !isSecondary?.(c));\n return nodeSearchText(node, searchChildren);\n }\n\n function visit(node: T): boolean {\n // A secondary node never drives a filter match — it's\n // effectively invisible to search. Still rendered when the\n // caller opens the parent manually. This is what lets a 28k-row\n // field tree stay searchable at the record level without \"field\n // name contains 'x'\" matches spamming the results.\n if (isSecondary?.(node)) return false;\n\n const key = getKey(node);\n const children = getChildren(node) ?? [];\n const childrenAllSecondary =\n children.length > 0 && children.every((child) => isSecondary?.(child));\n const matches = matchText(node, children).includes(normalizedQuery);\n const visibleChildren: T[] = [];\n\n for (const child of children) {\n if (visit(child)) visibleChildren.push(child);\n }\n\n if (matches) {\n if (children.length > 0) {\n filteredChildren.set(key, children);\n if (!childrenAllSecondary) forcedOpenKeys.add(key);\n }\n return true;\n }\n\n if (visibleChildren.length > 0) {\n filteredChildren.set(key, visibleChildren);\n forcedOpenKeys.add(key);\n return true;\n }\n\n return false;\n }\n\n return {\n roots: roots.filter((root) => visit(root)),\n filteredChildren,\n forcedOpenKeys,\n };\n}\n\nexport function Tree<T>({\n roots,\n empty,\n className,\n ariaLabel,\n showControls = true,\n showSearch = false,\n searchLabel,\n searchQuery,\n onSearchQueryChange,\n expandAll: controlledExpandAll,\n onExpandAllChange,\n toolbarClassName,\n actions,\n getSearchText,\n revealSelected = false,\n ...nodeProps\n}: TreeProps<T>) {\n const [internalExpandAll, setInternalExpandAll] = useState<boolean | null>(null);\n const [internalFilterQuery, setInternalFilterQuery] = useState(\"\");\n const filterQuery = searchQuery ?? internalFilterQuery;\n const setFilterQuery = (next: string) => {\n if (searchQuery !== undefined) onSearchQueryChange?.(next);\n else setInternalFilterQuery(next);\n };\n const basePaddingPx = nodeProps.basePaddingPx ?? 8;\n const isControlled = onExpandAllChange !== undefined;\n const expandAll = isControlled ? (controlledExpandAll ?? null) : internalExpandAll;\n const selectedKey = revealSelected && nodeProps.selected != null ? nodeProps.getKey(nodeProps.selected) : null;\n // revealKey drives the path reveal; it follows selectedKey except when the\n // selection came from clicking a row in this tree.\n const [reveal, setReveal] = useState({ selectedKey, revealKey: selectedKey, clickedKey: null as TreeKey | null });\n if (reveal.selectedKey !== selectedKey) {\n const fromTree = selectedKey !== null && selectedKey === reveal.clickedKey;\n setReveal({ selectedKey, revealKey: fromTree ? reveal.revealKey : selectedKey, clickedKey: null });\n }\n const revealKey = reveal.revealKey;\n const [revealInteraction, setRevealInteraction] = useState({\n selectedKey: null as TreeKey | null,\n overrides: new Map<TreeKey, boolean>(),\n bulk: false,\n });\n const previousExpandAll = useRef(expandAll);\n useEffect(() => {\n if (previousExpandAll.current === expandAll) return;\n previousExpandAll.current = expandAll;\n setRevealInteraction({ selectedKey: revealKey, overrides: new Map(), bulk: true });\n }, [expandAll, revealKey]);\n const totalEdges = useMemo(\n () => countTreeEdges(roots, nodeProps.getChildren),\n [roots, nodeProps.getChildren],\n );\n const showFilter = showSearch || totalEdges > 20 || Boolean(searchQuery);\n const activeFilter = showFilter ? filterQuery : \"\";\n const filteredTree = useMemo(\n () =>\n filterTreeRoots(\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ),\n [\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ],\n );\n const treeRoots = filteredTree.roots;\n const filteredChildren = filteredTree.filteredChildren;\n const revealPath = useMemo(\n () =>\n revealSelected && revealKey !== null\n ? selectionPath(roots, nodeProps.getChildren, nodeProps.getKey, revealKey)\n : null,\n [revealSelected, roots, nodeProps.getChildren, nodeProps.getKey, revealKey],\n );\n const activeReveal = !activeFilter.trim() && !(revealInteraction.selectedKey === revealKey && revealInteraction.bulk);\n const revealOverrides = revealInteraction.selectedKey === revealKey ? revealInteraction.overrides : null;\n const onSelect = nodeProps.onSelect;\n const selectFromTree = onSelect\n ? (node: T) => {\n setReveal((current) => ({ ...current, clickedKey: nodeProps.getKey(node) }));\n onSelect(node);\n }\n : undefined;\n const effectiveGetChildren = filteredChildren\n ? (node: T) => filteredChildren.get(nodeProps.getKey(node)) ?? []\n : nodeProps.getChildren;\n const effectiveExpandAll = expandAll;\n const effectiveEmpty = activeFilter.trim() ? (\n <div className=\"px-3 py-4 text-sm text-muted-foreground\">No matching tree nodes.</div>\n ) : (\n empty\n );\n const showControlButtons = showControls && roots.length > 0;\n const showVirtualRow = showFilter || showControlButtons || actions != null;\n const setExpandAll = (next: boolean | null) => {\n setRevealInteraction({ selectedKey: revealKey, overrides: new Map(), bulk: true });\n if (isControlled) onExpandAllChange?.(next);\n else setInternalExpandAll(next);\n };\n\n if (treeRoots.length === 0 && !showVirtualRow) return <>{effectiveEmpty ?? null}</>;\n\n return (\n <div className={cn(\"flex flex-col min-h-0\", className)}>\n <div className=\"min-h-0 flex-1 overflow-auto\">\n {showVirtualRow && (\n <div\n role=\"presentation\"\n className={cn(\n \"sticky top-0 z-10 flex items-center gap-1.5 border-b border-border/70 bg-background/95 py-1 pr-2 text-sm backdrop-blur supports-[backdrop-filter]:bg-background/80\",\n toolbarClassName,\n )}\n style={{ paddingLeft: `${basePaddingPx}px` }}\n >\n {showFilter ? (\n <Icon icon={UiSearch} className=\"w-3 shrink-0 text-xs text-muted-foreground\" />\n ) : (\n <span className=\"w-3 shrink-0\" aria-hidden />\n )}\n\n {showFilter ? (\n <label className=\"flex min-w-0 flex-1 items-center gap-2 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground shadow-sm\">\n <input\n type=\"search\"\n value={filterQuery}\n onChange={(event) => setFilterQuery(event.target.value)}\n placeholder={searchLabel ?? \"Filter tree\"}\n className=\"h-5 w-full min-w-0 border-0 bg-transparent p-0 text-xs outline-none placeholder:text-placeholder [&::-webkit-search-cancel-button]:appearance-none\"\n aria-label={searchLabel ?? \"Filter tree nodes\"}\n />\n {filterQuery && (\n <button\n type=\"button\"\n onClick={() => setFilterQuery(\"\")}\n className=\"inline-flex items-center rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground\"\n aria-label=\"Clear tree filter\"\n title=\"Clear tree filter\"\n >\n <Icon icon={UiClose} className=\"text-xs\" />\n </button>\n )}\n </label>\n ) : (\n <span className=\"flex-1\" />\n )}\n\n {(showControlButtons || actions != null) && (\n <div className=\"ml-auto flex items-center gap-1\">\n {actions}\n {showControlButtons && (\n <>\n <button\n type=\"button\"\n onClick={() => setExpandAll(true)}\n aria-pressed={effectiveExpandAll === true}\n aria-label=\"Expand all\"\n title=\"Expand all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === true && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiExpandAll} className=\"text-sm\" />\n </button>\n <button\n type=\"button\"\n onClick={() => setExpandAll(false)}\n aria-pressed={effectiveExpandAll === false}\n aria-label=\"Collapse all\"\n title=\"Collapse all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === false && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiCollapseAll} className=\"text-sm\" />\n </button>\n </>\n )}\n </div>\n )}\n </div>\n )}\n\n {treeRoots.length === 0 ? (\n (effectiveEmpty ?? null)\n ) : (\n <div role=\"tree\" aria-label={ariaLabel}>\n {treeRoots.map((root) => (\n <TreeNode<T>\n {...nodeProps}\n {...(selectFromTree ? { onSelect: selectFromTree } : {})}\n key={nodeProps.getKey(root)}\n node={root}\n expandAll={effectiveExpandAll}\n forcedOpenKeys={filteredTree.forcedOpenKeys}\n revealPath={activeReveal ? revealPath : null}\n revealOverrides={revealOverrides}\n onRevealToggle={(key, open) => setRevealInteraction((current) => {\n const overrides = new Map(current.selectedKey === revealKey ? current.overrides : []);\n overrides.set(key, open);\n return { selectedKey: revealKey, overrides, bulk: false };\n })}\n getChildren={effectiveGetChildren}\n />\n ))}\n </div>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAoEA,SAAS,cACP,OACA,aACA,QACA,WACqC;CACrC,MAAM,uBAAO,IAAI,IAA6B;CAC9C,MAAM,SAAS,SAAqB;EAClC,IAAI,OAAO,IAAI,MAAM,WAAW;GAC9B,KAAK,IAAI,WAAW,IAAI;GACxB,OAAO;EACT;EACA,KAAK,MAAM,SAAS,YAAY,IAAI,KAAK,CAAC,GACxC,IAAI,MAAM,KAAK,GAAG;GAChB,KAAK,IAAI,OAAO,IAAI,GAAG,OAAO,KAAK,CAAC;GACpC,OAAO;EACT;EAEF,OAAO;CACT;CACA,KAAK,MAAM,QAAQ,OACjB,IAAI,MAAM,IAAI,GAAG,OAAO;CAE1B,OAAO;AACT;AAQA,SAAS,eAAkB,OAAY,aAA0C;CAC/E,IAAI,QAAQ;CACZ,MAAM,QAAQ,CAAC,GAAG,KAAK;CAEvB,OAAO,MAAM,SAAS,GAAG;EAEvB,MAAM,WAAW,YADJ,MAAM,IACU,CAAI,KAAK,CAAC;EACvC,SAAS,SAAS;EAClB,MAAM,KAAK,GAAG,QAAQ;CACxB;CAEA,OAAO;AACT;AAEA,SAAS,sBACP,OACA,2BAAW,IAAI,IAAa,GAC5B,uBAAO,IAAI,IAAa,GAChB;CACR,IAAI,SAAS,QAAQ,SAAS,IAAI,KAAK,GAAG,OAAO;CAEjD,IACE,OAAO,UAAU,YACjB,OAAO,UAAU,YACjB,OAAO,UAAU,aACjB,OAAO,UAAU,UAEjB,OAAO,OAAO,KAAK;CAGrB,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,IAAI,KAAK,IAAI,KAAK,GAAG,OAAO;CAC5B,KAAK,IAAI,KAAK;CAEd,I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AA,CAACC,aAAAA,MAAD;QAAM,MAAMG,oBAAAA;QAAa,WAAU;OAAW,CAAA;MACxC,CAAA,GACR,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;OACE,MAAK;OACL,eAAe,aAAa,KAAK;OACjC,gBAAc,uBAAuB;OACrC,cAAW;OACX,OAAM;OACN,UAAU,aAAa,KAAK,CAAC,CAAC,SAAS;OACvC,WAAWJ,cAAAA,GACT,8KACA,uBAAuB,SAAS,kCAClC;OAEA,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,aAAAA,MAAD;QAAM,MAAMI,sBAAAA;QAAe,WAAU;OAAW,CAAA;MAC1C,CAAA,CACJ,EAAA,CAAA,CAED;;IAEJ;GAGN,CAAA,GAAA,UAAU,WAAW,IACnB,kBAAkB,OAEnB,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,MAAK;IAAO,cAAY;IAC1B,UAAA,UAAU,KAAK,SACd,iBAAA,GAAA,MAAA,cAAA,CAACC,iBAAAA,UAAD;KACE,GAAI;KACJ,GAAK,iBAAiB,EAAE,UAAU,eAAe,IAAI,CAAC;KACtD,KAAK,UAAU,OAAO,IAAI;KAC1B,MAAM;KACN,WAAW;KACX,gBAAgB,aAAa;KAC7B,YAAY,eAAe,aAAa;KACvB;KACjB,iBAAiB,KAAK,SAAS,sBAAsB,YAAY;MAC/D,MAAM,YAAY,IAAI,IAAI,QAAQ,gBAAgB,YAAY,QAAQ,YAAY,CAAC,CAAC;MACpF,UAAU,IAAI,KAAK,IAAI;MACvB,OAAO;OAAE,aAAa;OAAW;OAAW,MAAM;MAAM;KAC1D,CAAC;KACD,aAAa;IACd,CAAA,CACF;GACE,CAAA,CAEJ;;CACF,CAAA;AAET"}
|
|
1
|
+
{"version":3,"file":"Tree.cjs","names":["useState","useRef","useMemo","_Fragment","cn","Icon","UiSearch","UiClose","UiExpandAll","UiCollapseAll","TreeNode"],"sources":["../../src/data/Tree.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, useState, type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { Icon } from \"./Icon\";\nimport { UiClose, UiCollapseAll, UiExpandAll, UiSearch } from \"../icons\";\nimport { TreeNode, type TreeKey, type TreeNodeProps } from \"./TreeNode\";\n\nexport type TreeProps<T> = Omit<\n TreeNodeProps<T>,\n \"node\" | \"depth\" | \"expandAll\" | \"forcedOpenKeys\" | \"revealPath\" | \"revealOverrides\" | \"onRevealToggle\"\n> & {\n /** Root nodes to render. */\n roots: T[];\n /** Empty-state content when no roots are provided. */\n empty?: ReactNode;\n /** Classes applied to the tree root. */\n className?: string;\n /** Accessible name applied to the tree root. */\n ariaLabel?: string;\n /**\n * Render the Expand all / Collapse all toolbar above the tree. Enabled by\n * default. Set to false to suppress when the tree is tiny or the controls\n * are owned externally.\n */\n showControls?: boolean;\n /**\n * Search box visibility. Omitted: shown for trees with more than 20 edges or\n * a `searchQuery`. `true`: always shown. `false`: never shown — a parent that\n * owns the filter input still filters through `searchQuery`.\n */\n showSearch?: boolean;\n /** Placeholder and accessible name of the search box, e.g. \"Filter tests\". */\n searchLabel?: string;\n /** URL or parent-controlled search query. */\n searchQuery?: string;\n onSearchQueryChange?: (query: string) => void;\n /**\n * Externally controlled expand-all state. When provided together with\n * `onExpandAllChange`, the tree is controlled; otherwise it manages the\n * toolbar state internally.\n */\n expandAll?: boolean | null;\n /** Called when the toolbar expand-all state changes. */\n onExpandAllChange?: (next: boolean | null) => void;\n /** Classes applied to the search/control toolbar. */\n toolbarClassName?: string;\n /**\n * Extra controls rendered in the toolbar's right-hand group, before Expand\n * all / Collapse all. Providing actions shows the toolbar even when the tree\n * is too small for the filter and `showControls` is off.\n */\n actions?: ReactNode;\n /**\n * Override the text the filter matches against for a given node.\n * Defaults to a recursive walk of the node's own fields (excluding\n * its `children` and any secondary children), which works for\n * plain-shape trees but leaks text from nested domain objects —\n * e.g. a SQL Table's Field rows are marked secondary, yet the\n * parent record still carries `record.fields[].field` strings that\n * the default walker would collect. Callers that need precise\n * control over search behaviour should return only the text they\n * want surfaced (the node's own display label / id / type).\n */\n getSearchText?: (node: T) => string;\n /**\n * Reveal only the path to `selected` when it changes from outside the tree\n * (initial mount or navigation). Ancestors initially show the next path node;\n * manual expansion and collapse then take precedence until the next external\n * selection. Selecting a row by clicking it never re-reveals. Off by default.\n */\n revealSelected?: boolean;\n};\n\nfunction selectionPath<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n targetKey: TreeKey,\n): Map<TreeKey, TreeKey | null> | null {\n const path = new Map<TreeKey, TreeKey | null>();\n const visit = (node: T): boolean => {\n if (getKey(node) === targetKey) {\n path.set(targetKey, null);\n return true;\n }\n for (const child of getChildren(node) ?? []) {\n if (visit(child)) {\n path.set(getKey(node), getKey(child));\n return true;\n }\n }\n return false;\n };\n for (const root of roots) {\n if (visit(root)) return path;\n }\n return null;\n}\n\n// Edge counting, search-text collection and filtering all walk the tree through\n// the synchronous `getChildren` only. A lazy node (one declared via\n// `hasMoreChildren` whose children have not been fetched yet) therefore\n// contributes no edges and no search text until the operator expands it — so it\n// is invisible to \"expand all\" and to the filter while still collapsed. This is\n// intentional: we never trigger network loads from bulk/search operations.\nfunction countTreeEdges<T>(roots: T[], getChildren: TreeProps<T>[\"getChildren\"]) {\n let total = 0;\n const stack = [...roots];\n\n while (stack.length > 0) {\n const node = stack.pop()!;\n const children = getChildren(node) ?? [];\n total += children.length;\n stack.push(...children);\n }\n\n return total;\n}\n\nfunction collectTreeSearchText(\n value: unknown,\n excluded = new Set<unknown>(),\n seen = new Set<unknown>(),\n): string {\n if (value == null || excluded.has(value)) return \"\";\n\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\"\n ) {\n return String(value);\n }\n\n if (typeof value !== \"object\") return \"\";\n if (seen.has(value)) return \"\";\n seen.add(value);\n\n if (Array.isArray(value)) {\n return value\n .map((entry) => collectTreeSearchText(entry, excluded, seen))\n .filter(Boolean)\n .join(\" \");\n }\n\n const preferredKeys = [\"label\", \"name\", \"title\", \"text\", \"plain\", \"id\", \"content\"];\n const record = value as Record<string, unknown>;\n const chunks: string[] = [];\n\n for (const key of preferredKeys) {\n if (!(key in record)) continue;\n const text = collectTreeSearchText(record[key], excluded, seen);\n if (text) chunks.push(text);\n }\n\n for (const [key, entry] of Object.entries(record)) {\n if (key === \"children\" || preferredKeys.includes(key)) continue;\n const text = collectTreeSearchText(entry, excluded, seen);\n if (text) chunks.push(text);\n }\n\n return chunks.join(\" \");\n}\n\nfunction nodeSearchText<T>(node: T, children: ReturnType<TreeProps<T>[\"getChildren\"]>) {\n const excluded = new Set<unknown>();\n if (children) excluded.add(children);\n return collectTreeSearchText(node, excluded).trim().toLowerCase();\n}\n\nfunction filterTreeRoots<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n query: string,\n isSecondary?: (node: T) => boolean,\n getSearchText?: (node: T) => string,\n) {\n const normalizedQuery = query.trim().toLowerCase();\n if (!normalizedQuery) {\n return {\n roots,\n filteredChildren: null as Map<string | number, T[]> | null,\n forcedOpenKeys: null as Set<string | number> | null,\n };\n }\n\n const filteredChildren = new Map<string | number, T[]>();\n const forcedOpenKeys = new Set<string | number>();\n\n function matchText(node: T, children: T[]): string {\n // Honour the caller-supplied text extractor first — it's the\n // only way to get precise control over what the filter sees when\n // the node carries domain data whose fields would otherwise leak\n // into the default walker.\n if (getSearchText) return getSearchText(node).trim().toLowerCase();\n // Match-text skips secondary children so e.g. a Table's search\n // text only draws from the Table itself, not from its Field\n // rows. The Table is primary, so its own text still counts.\n const searchChildren = children.filter((c) => !isSecondary?.(c));\n return nodeSearchText(node, searchChildren);\n }\n\n function visit(node: T): boolean {\n // A secondary node never drives a filter match — it's\n // effectively invisible to search. Still rendered when the\n // caller opens the parent manually. This is what lets a 28k-row\n // field tree stay searchable at the record level without \"field\n // name contains 'x'\" matches spamming the results.\n if (isSecondary?.(node)) return false;\n\n const key = getKey(node);\n const children = getChildren(node) ?? [];\n const childrenAllSecondary =\n children.length > 0 && children.every((child) => isSecondary?.(child));\n const matches = matchText(node, children).includes(normalizedQuery);\n const visibleChildren: T[] = [];\n\n for (const child of children) {\n if (visit(child)) visibleChildren.push(child);\n }\n\n if (matches) {\n if (children.length > 0) {\n filteredChildren.set(key, children);\n if (!childrenAllSecondary) forcedOpenKeys.add(key);\n }\n return true;\n }\n\n if (visibleChildren.length > 0) {\n filteredChildren.set(key, visibleChildren);\n forcedOpenKeys.add(key);\n return true;\n }\n\n return false;\n }\n\n return {\n roots: roots.filter((root) => visit(root)),\n filteredChildren,\n forcedOpenKeys,\n };\n}\n\nexport function Tree<T>({\n roots,\n empty,\n className,\n ariaLabel,\n showControls = true,\n showSearch,\n searchLabel,\n searchQuery,\n onSearchQueryChange,\n expandAll: controlledExpandAll,\n onExpandAllChange,\n toolbarClassName,\n actions,\n getSearchText,\n revealSelected = false,\n ...nodeProps\n}: TreeProps<T>) {\n const [internalExpandAll, setInternalExpandAll] = useState<boolean | null>(null);\n const [internalFilterQuery, setInternalFilterQuery] = useState(\"\");\n const filterQuery = searchQuery ?? internalFilterQuery;\n const setFilterQuery = (next: string) => {\n if (searchQuery !== undefined) onSearchQueryChange?.(next);\n else setInternalFilterQuery(next);\n };\n const basePaddingPx = nodeProps.basePaddingPx ?? 8;\n const isControlled = onExpandAllChange !== undefined;\n const expandAll = isControlled ? (controlledExpandAll ?? null) : internalExpandAll;\n const selectedKey = revealSelected && nodeProps.selected != null ? nodeProps.getKey(nodeProps.selected) : null;\n // revealKey drives the path reveal; it follows selectedKey except when the\n // selection came from clicking a row in this tree.\n const [reveal, setReveal] = useState({ selectedKey, revealKey: selectedKey, clickedKey: null as TreeKey | null });\n const [revealInteraction, setRevealInteraction] = useState({\n selectedKey: null as TreeKey | null,\n overrides: new Map<TreeKey, boolean>(),\n bulk: false,\n });\n if (reveal.selectedKey !== selectedKey) {\n const fromTree = selectedKey !== null && selectedKey === reveal.clickedKey;\n setReveal({ selectedKey, revealKey: fromTree ? reveal.revealKey : selectedKey, clickedKey: null });\n // An external selection is a fresh reveal: toggles and bulk controls made\n // for an earlier visit to the same key no longer apply.\n if (!fromTree) setRevealInteraction({ selectedKey: null, overrides: new Map(), bulk: false });\n }\n const revealKey = reveal.revealKey;\n const previousExpandAll = useRef(expandAll);\n useEffect(() => {\n if (previousExpandAll.current === expandAll) return;\n previousExpandAll.current = expandAll;\n setRevealInteraction({ selectedKey: revealKey, overrides: new Map(), bulk: true });\n }, [expandAll, revealKey]);\n const totalEdges = useMemo(\n () => countTreeEdges(roots, nodeProps.getChildren),\n [roots, nodeProps.getChildren],\n );\n const showFilter = showSearch ?? (totalEdges > 20 || Boolean(searchQuery));\n const activeFilter = showFilter || showSearch === false ? filterQuery : \"\";\n const filteredTree = useMemo(\n () =>\n filterTreeRoots(\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ),\n [\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ],\n );\n const treeRoots = filteredTree.roots;\n const filteredChildren = filteredTree.filteredChildren;\n const revealPath = useMemo(\n () =>\n revealSelected && revealKey !== null\n ? selectionPath(roots, nodeProps.getChildren, nodeProps.getKey, revealKey)\n : null,\n [revealSelected, roots, nodeProps.getChildren, nodeProps.getKey, revealKey],\n );\n const activeReveal = !activeFilter.trim() && !(revealInteraction.selectedKey === revealKey && revealInteraction.bulk);\n const revealOverrides = revealInteraction.selectedKey === revealKey ? revealInteraction.overrides : null;\n const onSelect = nodeProps.onSelect;\n const selectFromTree = onSelect\n ? (node: T) => {\n setReveal((current) => ({ ...current, clickedKey: nodeProps.getKey(node) }));\n onSelect(node);\n }\n : undefined;\n const effectiveGetChildren = filteredChildren\n ? (node: T) => filteredChildren.get(nodeProps.getKey(node)) ?? []\n : nodeProps.getChildren;\n const effectiveExpandAll = expandAll;\n const effectiveEmpty = activeFilter.trim() ? (\n <div className=\"px-3 py-4 text-sm text-muted-foreground\">No matching tree nodes.</div>\n ) : (\n empty\n );\n const showControlButtons = showControls && roots.length > 0;\n const showVirtualRow = showFilter || showControlButtons || actions != null;\n const setExpandAll = (next: boolean | null) => {\n setRevealInteraction({ selectedKey: revealKey, overrides: new Map(), bulk: true });\n if (isControlled) onExpandAllChange?.(next);\n else setInternalExpandAll(next);\n };\n\n if (treeRoots.length === 0 && !showVirtualRow) return <>{effectiveEmpty ?? null}</>;\n\n return (\n <div className={cn(\"flex flex-col min-h-0\", className)}>\n <div className=\"min-h-0 flex-1 overflow-auto\">\n {showVirtualRow && (\n <div\n role=\"presentation\"\n className={cn(\n \"sticky top-0 z-10 flex items-center gap-1.5 border-b border-border/70 bg-background/95 py-1 pr-2 text-sm backdrop-blur supports-[backdrop-filter]:bg-background/80\",\n toolbarClassName,\n )}\n style={{ paddingLeft: `${basePaddingPx}px` }}\n >\n {showFilter ? (\n <Icon icon={UiSearch} className=\"w-3 shrink-0 text-xs text-muted-foreground\" />\n ) : (\n <span className=\"w-3 shrink-0\" aria-hidden />\n )}\n\n {showFilter ? (\n <label className=\"flex min-w-0 flex-1 items-center gap-2 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground shadow-sm\">\n <input\n type=\"search\"\n value={filterQuery}\n onChange={(event) => setFilterQuery(event.target.value)}\n placeholder={searchLabel ?? \"Filter tree\"}\n className=\"h-5 w-full min-w-0 border-0 bg-transparent p-0 text-xs outline-none placeholder:text-placeholder [&::-webkit-search-cancel-button]:appearance-none\"\n aria-label={searchLabel ?? \"Filter tree nodes\"}\n />\n {filterQuery && (\n <button\n type=\"button\"\n onClick={() => setFilterQuery(\"\")}\n className=\"inline-flex items-center rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground\"\n aria-label=\"Clear tree filter\"\n title=\"Clear tree filter\"\n >\n <Icon icon={UiClose} className=\"text-xs\" />\n </button>\n )}\n </label>\n ) : (\n <span className=\"flex-1\" />\n )}\n\n {(showControlButtons || actions != null) && (\n <div className=\"ml-auto flex items-center gap-1\">\n {actions}\n {showControlButtons && (\n <>\n <button\n type=\"button\"\n onClick={() => setExpandAll(true)}\n aria-pressed={effectiveExpandAll === true}\n aria-label=\"Expand all\"\n title=\"Expand all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === true && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiExpandAll} className=\"text-sm\" />\n </button>\n <button\n type=\"button\"\n onClick={() => setExpandAll(false)}\n aria-pressed={effectiveExpandAll === false}\n aria-label=\"Collapse all\"\n title=\"Collapse all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === false && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiCollapseAll} className=\"text-sm\" />\n </button>\n </>\n )}\n </div>\n )}\n </div>\n )}\n\n {treeRoots.length === 0 ? (\n (effectiveEmpty ?? null)\n ) : (\n <div role=\"tree\" aria-label={ariaLabel}>\n {treeRoots.map((root) => (\n <TreeNode<T>\n {...nodeProps}\n {...(selectFromTree ? { onSelect: selectFromTree } : {})}\n key={nodeProps.getKey(root)}\n node={root}\n expandAll={effectiveExpandAll}\n forcedOpenKeys={filteredTree.forcedOpenKeys}\n revealPath={activeReveal ? revealPath : null}\n revealOverrides={revealOverrides}\n onRevealToggle={(key, open) => setRevealInteraction((current) => {\n const overrides = new Map(current.selectedKey === revealKey ? current.overrides : []);\n overrides.set(key, open);\n return { selectedKey: revealKey, overrides, bulk: false };\n })}\n getChildren={effectiveGetChildren}\n />\n ))}\n </div>\n )}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A;QAAa,WAAU;OAAW,CAAA;MACxC,CAAA,GACR,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;OACE,MAAK;OACL,eAAe,aAAa,KAAK;OACjC,gBAAc,uBAAuB;OACrC,cAAW;OACX,OAAM;OACN,UAAU,aAAa,KAAK,CAAC,CAAC,SAAS;OACvC,WAAWJ,cAAAA,GACT,8KACA,uBAAuB,SAAS,kCAClC;OAEA,UAAA,iBAAA,GAAA,kBAAA,IAAA,CAACC,aAAAA,MAAD;QAAM,MAAMI,sBAAAA;QAAe,WAAU;OAAW,CAAA;MAC1C,CAAA,CACJ,EAAA,CAAA,CAED;;IAEJ;GAGN,CAAA,GAAA,UAAU,WAAW,IACnB,kBAAkB,OAEnB,iBAAA,GAAA,kBAAA,IAAA,CAAC,OAAD;IAAK,MAAK;IAAO,cAAY;IAC1B,UAAA,UAAU,KAAK,SACd,iBAAA,GAAA,MAAA,cAAA,CAACC,iBAAAA,UAAD;KACE,GAAI;KACJ,GAAK,iBAAiB,EAAE,UAAU,eAAe,IAAI,CAAC;KACtD,KAAK,UAAU,OAAO,IAAI;KAC1B,MAAM;KACN,WAAW;KACX,gBAAgB,aAAa;KAC7B,YAAY,eAAe,aAAa;KACvB;KACjB,iBAAiB,KAAK,SAAS,sBAAsB,YAAY;MAC/D,MAAM,YAAY,IAAI,IAAI,QAAQ,gBAAgB,YAAY,QAAQ,YAAY,CAAC,CAAC;MACpF,UAAU,IAAI,KAAK,IAAI;MACvB,OAAO;OAAE,aAAa;OAAW;OAAW,MAAM;MAAM;KAC1D,CAAC;KACD,aAAa;IACd,CAAA,CACF;GACE,CAAA,CAEJ;;CACF,CAAA;AAET"}
|
package/dist/data/Tree.d.ts
CHANGED
|
@@ -15,7 +15,11 @@ export type TreeProps<T> = Omit<TreeNodeProps<T>, "node" | "depth" | "expandAll"
|
|
|
15
15
|
* are owned externally.
|
|
16
16
|
*/
|
|
17
17
|
showControls?: boolean;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Search box visibility. Omitted: shown for trees with more than 20 edges or
|
|
20
|
+
* a `searchQuery`. `true`: always shown. `false`: never shown — a parent that
|
|
21
|
+
* owns the filter input still filters through `searchQuery`.
|
|
22
|
+
*/
|
|
19
23
|
showSearch?: boolean;
|
|
20
24
|
/** Placeholder and accessible name of the search box, e.g. "Filter tests". */
|
|
21
25
|
searchLabel?: string;
|
package/dist/data/Tree.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../src/data/Tree.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAI7E,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAExE,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,IAAI,CAC7B,aAAa,CAAC,CAAC,CAAC,EAChB,MAAM,GAAG,OAAO,GAAG,WAAW,GAAG,gBAAgB,GAAG,YAAY,GAAG,iBAAiB,GAAG,gBAAgB,CACxG,GAAG;IACF,4BAA4B;IAC5B,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,sDAAsD;IACtD,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,wCAAwC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB
|
|
1
|
+
{"version":3,"file":"Tree.d.ts","sourceRoot":"","sources":["../../src/data/Tree.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAwC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAI7E,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAExE,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,IAAI,CAC7B,aAAa,CAAC,CAAC,CAAC,EAChB,MAAM,GAAG,OAAO,GAAG,W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,CAAC,CAAC,CAAC,+BA+Md"}
|
package/dist/data/Tree.js
CHANGED
|
@@ -110,7 +110,7 @@ function filterTreeRoots(roots, getChildren, getKey, query, isSecondary, getSear
|
|
|
110
110
|
forcedOpenKeys
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
function Tree({ roots, empty, className, ariaLabel, showControls = true, showSearch
|
|
113
|
+
function Tree({ roots, empty, className, ariaLabel, showControls = true, showSearch, searchLabel, searchQuery, onSearchQueryChange, expandAll: controlledExpandAll, onExpandAllChange, toolbarClassName, actions, getSearchText, revealSelected = false, ...nodeProps }) {
|
|
114
114
|
const [internalExpandAll, setInternalExpandAll] = useState(null);
|
|
115
115
|
const [internalFilterQuery, setInternalFilterQuery] = useState("");
|
|
116
116
|
const filterQuery = searchQuery ?? internalFilterQuery;
|
|
@@ -127,17 +127,25 @@ function Tree({ roots, empty, className, ariaLabel, showControls = true, showSea
|
|
|
127
127
|
revealKey: selectedKey,
|
|
128
128
|
clickedKey: null
|
|
129
129
|
});
|
|
130
|
-
if (reveal.selectedKey !== selectedKey) setReveal({
|
|
131
|
-
selectedKey,
|
|
132
|
-
revealKey: selectedKey !== null && selectedKey === reveal.clickedKey ? reveal.revealKey : selectedKey,
|
|
133
|
-
clickedKey: null
|
|
134
|
-
});
|
|
135
|
-
const revealKey = reveal.revealKey;
|
|
136
130
|
const [revealInteraction, setRevealInteraction] = useState({
|
|
137
131
|
selectedKey: null,
|
|
138
132
|
overrides: /* @__PURE__ */ new Map(),
|
|
139
133
|
bulk: false
|
|
140
134
|
});
|
|
135
|
+
if (reveal.selectedKey !== selectedKey) {
|
|
136
|
+
const fromTree = selectedKey !== null && selectedKey === reveal.clickedKey;
|
|
137
|
+
setReveal({
|
|
138
|
+
selectedKey,
|
|
139
|
+
revealKey: fromTree ? reveal.revealKey : selectedKey,
|
|
140
|
+
clickedKey: null
|
|
141
|
+
});
|
|
142
|
+
if (!fromTree) setRevealInteraction({
|
|
143
|
+
selectedKey: null,
|
|
144
|
+
overrides: /* @__PURE__ */ new Map(),
|
|
145
|
+
bulk: false
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
const revealKey = reveal.revealKey;
|
|
141
149
|
const previousExpandAll = useRef(expandAll);
|
|
142
150
|
useEffect(() => {
|
|
143
151
|
if (previousExpandAll.current === expandAll) return;
|
|
@@ -149,8 +157,8 @@ function Tree({ roots, empty, className, ariaLabel, showControls = true, showSea
|
|
|
149
157
|
});
|
|
150
158
|
}, [expandAll, revealKey]);
|
|
151
159
|
const totalEdges = useMemo(() => countTreeEdges(roots, nodeProps.getChildren), [roots, nodeProps.getChildren]);
|
|
152
|
-
const showFilter = showSearch
|
|
153
|
-
const activeFilter = showFilter ? filterQuery : "";
|
|
160
|
+
const showFilter = showSearch ?? (totalEdges > 20 || Boolean(searchQuery));
|
|
161
|
+
const activeFilter = showFilter || showSearch === false ? filterQuery : "";
|
|
154
162
|
const filteredTree = useMemo(() => filterTreeRoots(roots, nodeProps.getChildren, nodeProps.getKey, activeFilter, nodeProps.isSecondary, getSearchText), [
|
|
155
163
|
roots,
|
|
156
164
|
nodeProps.getChildren,
|
package/dist/data/Tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tree.js","names":["_Fragment"],"sources":["../../src/data/Tree.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, useState, type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { Icon } from \"./Icon\";\nimport { UiClose, UiCollapseAll, UiExpandAll, UiSearch } from \"../icons\";\nimport { TreeNode, type TreeKey, type TreeNodeProps } from \"./TreeNode\";\n\nexport type TreeProps<T> = Omit<\n TreeNodeProps<T>,\n \"node\" | \"depth\" | \"expandAll\" | \"forcedOpenKeys\" | \"revealPath\" | \"revealOverrides\" | \"onRevealToggle\"\n> & {\n /** Root nodes to render. */\n roots: T[];\n /** Empty-state content when no roots are provided. */\n empty?: ReactNode;\n /** Classes applied to the tree root. */\n className?: string;\n /** Accessible name applied to the tree root. */\n ariaLabel?: string;\n /**\n * Render the Expand all / Collapse all toolbar above the tree. Enabled by\n * default. Set to false to suppress when the tree is tiny or the controls\n * are owned externally.\n */\n showControls?: boolean;\n /** Keep search visible for small or empty trees. */\n showSearch?: boolean;\n /** Placeholder and accessible name of the search box, e.g. \"Filter tests\". */\n searchLabel?: string;\n /** URL or parent-controlled search query. */\n searchQuery?: string;\n onSearchQueryChange?: (query: string) => void;\n /**\n * Externally controlled expand-all state. When provided together with\n * `onExpandAllChange`, the tree is controlled; otherwise it manages the\n * toolbar state internally.\n */\n expandAll?: boolean | null;\n /** Called when the toolbar expand-all state changes. */\n onExpandAllChange?: (next: boolean | null) => void;\n /** Classes applied to the search/control toolbar. */\n toolbarClassName?: string;\n /**\n * Extra controls rendered in the toolbar's right-hand group, before Expand\n * all / Collapse all. Providing actions shows the toolbar even when the tree\n * is too small for the filter and `showControls` is off.\n */\n actions?: ReactNode;\n /**\n * Override the text the filter matches against for a given node.\n * Defaults to a recursive walk of the node's own fields (excluding\n * its `children` and any secondary children), which works for\n * plain-shape trees but leaks text from nested domain objects —\n * e.g. a SQL Table's Field rows are marked secondary, yet the\n * parent record still carries `record.fields[].field` strings that\n * the default walker would collect. Callers that need precise\n * control over search behaviour should return only the text they\n * want surfaced (the node's own display label / id / type).\n */\n getSearchText?: (node: T) => string;\n /**\n * Reveal only the path to `selected` when it changes from outside the tree\n * (initial mount or navigation). Ancestors initially show the next path node;\n * manual expansion and collapse then take precedence until the next external\n * selection. Selecting a row by clicking it never re-reveals. Off by default.\n */\n revealSelected?: boolean;\n};\n\nfunction selectionPath<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n targetKey: TreeKey,\n): Map<TreeKey, TreeKey | null> | null {\n const path = new Map<TreeKey, TreeKey | null>();\n const visit = (node: T): boolean => {\n if (getKey(node) === targetKey) {\n path.set(targetKey, null);\n return true;\n }\n for (const child of getChildren(node) ?? []) {\n if (visit(child)) {\n path.set(getKey(node), getKey(child));\n return true;\n }\n }\n return false;\n };\n for (const root of roots) {\n if (visit(root)) return path;\n }\n return null;\n}\n\n// Edge counting, search-text collection and filtering all walk the tree through\n// the synchronous `getChildren` only. A lazy node (one declared via\n// `hasMoreChildren` whose children have not been fetched yet) therefore\n// contributes no edges and no search text until the operator expands it — so it\n// is invisible to \"expand all\" and to the filter while still collapsed. This is\n// intentional: we never trigger network loads from bulk/search operations.\nfunction countTreeEdges<T>(roots: T[], getChildren: TreeProps<T>[\"getChildren\"]) {\n let total = 0;\n const stack = [...roots];\n\n while (stack.length > 0) {\n const node = stack.pop()!;\n const children = getChildren(node) ?? [];\n total += children.length;\n stack.push(...children);\n }\n\n return total;\n}\n\nfunction collectTreeSearchText(\n value: unknown,\n excluded = new Set<unknown>(),\n seen = new Set<unknown>(),\n): string {\n if (value == null || excluded.has(value)) return \"\";\n\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\"\n ) {\n return String(value);\n }\n\n if (typeof value !== \"object\") return \"\";\n if (seen.has(value)) return \"\";\n seen.add(value);\n\n if (Array.isArray(value)) {\n return value\n .map((entry) => collectTreeSearchText(entry, excluded, seen))\n .filter(Boolean)\n .join(\" \");\n }\n\n const preferredKeys = [\"label\", \"name\", \"title\", \"text\", \"plain\", \"id\", \"content\"];\n const record = value as Record<string, unknown>;\n const chunks: string[] = [];\n\n for (const key of preferredKeys) {\n if (!(key in record)) continue;\n const text = collectTreeSearchText(record[key], excluded, seen);\n if (text) chunks.push(text);\n }\n\n for (const [key, entry] of Object.entries(record)) {\n if (key === \"children\" || preferredKeys.includes(key)) continue;\n const text = collectTreeSearchText(entry, excluded, seen);\n if (text) chunks.push(text);\n }\n\n return chunks.join(\" \");\n}\n\nfunction nodeSearchText<T>(node: T, children: ReturnType<TreeProps<T>[\"getChildren\"]>) {\n const excluded = new Set<unknown>();\n if (children) excluded.add(children);\n return collectTreeSearchText(node, excluded).trim().toLowerCase();\n}\n\nfunction filterTreeRoots<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n query: string,\n isSecondary?: (node: T) => boolean,\n getSearchText?: (node: T) => string,\n) {\n const normalizedQuery = query.trim().toLowerCase();\n if (!normalizedQuery) {\n return {\n roots,\n filteredChildren: null as Map<string | number, T[]> | null,\n forcedOpenKeys: null as Set<string | number> | null,\n };\n }\n\n const filteredChildren = new Map<string | number, T[]>();\n const forcedOpenKeys = new Set<string | number>();\n\n function matchText(node: T, children: T[]): string {\n // Honour the caller-supplied text extractor first — it's the\n // only way to get precise control over what the filter sees when\n // the node carries domain data whose fields would otherwise leak\n // into the default walker.\n if (getSearchText) return getSearchText(node).trim().toLowerCase();\n // Match-text skips secondary children so e.g. a Table's search\n // text only draws from the Table itself, not from its Field\n // rows. The Table is primary, so its own text still counts.\n const searchChildren = children.filter((c) => !isSecondary?.(c));\n return nodeSearchText(node, searchChildren);\n }\n\n function visit(node: T): boolean {\n // A secondary node never drives a filter match — it's\n // effectively invisible to search. Still rendered when the\n // caller opens the parent manually. This is what lets a 28k-row\n // field tree stay searchable at the record level without \"field\n // name contains 'x'\" matches spamming the results.\n if (isSecondary?.(node)) return false;\n\n const key = getKey(node);\n const children = getChildren(node) ?? [];\n const childrenAllSecondary =\n children.length > 0 && children.every((child) => isSecondary?.(child));\n const matches = matchText(node, children).includes(normalizedQuery);\n const visibleChildren: T[] = [];\n\n for (const child of children) {\n if (visit(child)) visibleChildren.push(child);\n }\n\n if (matches) {\n if (children.length > 0) {\n filteredChildren.set(key, children);\n if (!childrenAllSecondary) forcedOpenKeys.add(key);\n }\n return true;\n }\n\n if (visibleChildren.length > 0) {\n filteredChildren.set(key, visibleChildren);\n forcedOpenKeys.add(key);\n return true;\n }\n\n return false;\n }\n\n return {\n roots: roots.filter((root) => visit(root)),\n filteredChildren,\n forcedOpenKeys,\n };\n}\n\nexport function Tree<T>({\n roots,\n empty,\n className,\n ariaLabel,\n showControls = true,\n showSearch = false,\n searchLabel,\n searchQuery,\n onSearchQueryChange,\n expandAll: controlledExpandAll,\n onExpandAllChange,\n toolbarClassName,\n actions,\n getSearchText,\n revealSelected = false,\n ...nodeProps\n}: TreeProps<T>) {\n const [internalExpandAll, setInternalExpandAll] = useState<boolean | null>(null);\n const [internalFilterQuery, setInternalFilterQuery] = useState(\"\");\n const filterQuery = searchQuery ?? internalFilterQuery;\n const setFilterQuery = (next: string) => {\n if (searchQuery !== undefined) onSearchQueryChange?.(next);\n else setInternalFilterQuery(next);\n };\n const basePaddingPx = nodeProps.basePaddingPx ?? 8;\n const isControlled = onExpandAllChange !== undefined;\n const expandAll = isControlled ? (controlledExpandAll ?? null) : internalExpandAll;\n const selectedKey = revealSelected && nodeProps.selected != null ? nodeProps.getKey(nodeProps.selected) : null;\n // revealKey drives the path reveal; it follows selectedKey except when the\n // selection came from clicking a row in this tree.\n const [reveal, setReveal] = useState({ selectedKey, revealKey: selectedKey, clickedKey: null as TreeKey | null });\n if (reveal.selectedKey !== selectedKey) {\n const fromTree = selectedKey !== null && selectedKey === reveal.clickedKey;\n setReveal({ selectedKey, revealKey: fromTree ? reveal.revealKey : selectedKey, clickedKey: null });\n }\n const revealKey = reveal.revealKey;\n const [revealInteraction, setRevealInteraction] = useState({\n selectedKey: null as TreeKey | null,\n overrides: new Map<TreeKey, boolean>(),\n bulk: false,\n });\n const previousExpandAll = useRef(expandAll);\n useEffect(() => {\n if (previousExpandAll.current === expandAll) return;\n previousExpandAll.current = expandAll;\n setRevealInteraction({ selectedKey: revealKey, overrides: new Map(), bulk: true });\n }, [expandAll, revealKey]);\n const totalEdges = useMemo(\n () => countTreeEdges(roots, nodeProps.getChildren),\n [roots, nodeProps.getChildren],\n );\n const showFilter = showSearch || totalEdges > 20 || Boolean(searchQuery);\n const activeFilter = showFilter ? filterQuery : \"\";\n const filteredTree = useMemo(\n () =>\n filterTreeRoots(\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ),\n [\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ],\n );\n const treeRoots = filteredTree.roots;\n const filteredChildren = filteredTree.filteredChildren;\n const revealPath = useMemo(\n () =>\n revealSelected && revealKey !== null\n ? selectionPath(roots, nodeProps.getChildren, nodeProps.getKey, revealKey)\n : null,\n [revealSelected, roots, nodeProps.getChildren, nodeProps.getKey, revealKey],\n );\n const activeReveal = !activeFilter.trim() && !(revealInteraction.selectedKey === revealKey && revealInteraction.bulk);\n const revealOverrides = revealInteraction.selectedKey === revealKey ? revealInteraction.overrides : null;\n const onSelect = nodeProps.onSelect;\n const selectFromTree = onSelect\n ? (node: T) => {\n setReveal((current) => ({ ...current, clickedKey: nodeProps.getKey(node) }));\n onSelect(node);\n }\n : undefined;\n const effectiveGetChildren = filteredChildren\n ? (node: T) => filteredChildren.get(nodeProps.getKey(node)) ?? []\n : nodeProps.getChildren;\n const effectiveExpandAll = expandAll;\n const effectiveEmpty = activeFilter.trim() ? (\n <div className=\"px-3 py-4 text-sm text-muted-foreground\">No matching tree nodes.</div>\n ) : (\n empty\n );\n const showControlButtons = showControls && roots.length > 0;\n const showVirtualRow = showFilter || showControlButtons || actions != null;\n const setExpandAll = (next: boolean | null) => {\n setRevealInteraction({ selectedKey: revealKey, overrides: new Map(), bulk: true });\n if (isControlled) onExpandAllChange?.(next);\n else setInternalExpandAll(next);\n };\n\n if (treeRoots.length === 0 && !showVirtualRow) return <>{effectiveEmpty ?? null}</>;\n\n return (\n <div className={cn(\"flex flex-col min-h-0\", className)}>\n <div className=\"min-h-0 flex-1 overflow-auto\">\n {showVirtualRow && (\n <div\n role=\"presentation\"\n className={cn(\n \"sticky top-0 z-10 flex items-center gap-1.5 border-b border-border/70 bg-background/95 py-1 pr-2 text-sm backdrop-blur supports-[backdrop-filter]:bg-background/80\",\n toolbarClassName,\n )}\n style={{ paddingLeft: `${basePaddingPx}px` }}\n >\n {showFilter ? (\n <Icon icon={UiSearch} className=\"w-3 shrink-0 text-xs text-muted-foreground\" />\n ) : (\n <span className=\"w-3 shrink-0\" aria-hidden />\n )}\n\n {showFilter ? (\n <label className=\"flex min-w-0 flex-1 items-center gap-2 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground shadow-sm\">\n <input\n type=\"search\"\n value={filterQuery}\n onChange={(event) => setFilterQuery(event.target.value)}\n placeholder={searchLabel ?? \"Filter tree\"}\n className=\"h-5 w-full min-w-0 border-0 bg-transparent p-0 text-xs outline-none placeholder:text-placeholder [&::-webkit-search-cancel-button]:appearance-none\"\n aria-label={searchLabel ?? \"Filter tree nodes\"}\n />\n {filterQuery && (\n <button\n type=\"button\"\n onClick={() => setFilterQuery(\"\")}\n className=\"inline-flex items-center rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground\"\n aria-label=\"Clear tree filter\"\n title=\"Clear tree filter\"\n >\n <Icon icon={UiClose} className=\"text-xs\" />\n </button>\n )}\n </label>\n ) : (\n <span className=\"flex-1\" />\n )}\n\n {(showControlButtons || actions != null) && (\n <div className=\"ml-auto flex items-center gap-1\">\n {actions}\n {showControlButtons && (\n <>\n <button\n type=\"button\"\n onClick={() => setExpandAll(true)}\n aria-pressed={effectiveExpandAll === true}\n aria-label=\"Expand all\"\n title=\"Expand all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === true && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiExpandAll} className=\"text-sm\" />\n </button>\n <button\n type=\"button\"\n onClick={() => setExpandAll(false)}\n aria-pressed={effectiveExpandAll === false}\n aria-label=\"Collapse all\"\n title=\"Collapse all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === false && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiCollapseAll} className=\"text-sm\" />\n </button>\n </>\n )}\n </div>\n )}\n </div>\n )}\n\n {treeRoots.length === 0 ? (\n (effectiveEmpty ?? null)\n ) : (\n <div role=\"tree\" aria-label={ariaLabel}>\n {treeRoots.map((root) => (\n <TreeNode<T>\n {...nodeProps}\n {...(selectFromTree ? { onSelect: selectFromTree } : {})}\n key={nodeProps.getKey(root)}\n node={root}\n expandAll={effectiveExpandAll}\n forcedOpenKeys={filteredTree.forcedOpenKeys}\n revealPath={activeReveal ? revealPath : null}\n revealOverrides={revealOverrides}\n onRevealToggle={(key, open) => setRevealInteraction((current) => {\n const overrides = new Map(current.selectedKey === revealKey ? current.overrides : []);\n overrides.set(key, open);\n return { selectedKey: revealKey, overrides, bulk: false };\n })}\n getChildren={effectiveGetChildren}\n />\n ))}\n </div>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAoEA,SAAS,cACP,OACA,aACA,QACA,WACqC;CACrC,MAAM,uBAAO,IAAI,IAA6B;CAC9C,MAAM,SAAS,SAAqB;EAClC,IAAI,OAAO,IAAI,MAAM,WAAW;GAC9B,KAAK,IAAI,WAAW,IAAI;GACxB,OAAO;EACT;EACA,KAAK,MAAM,SAAS,YAAY,IAAI,KAAK,CAAC,GACxC,IAAI,MAAM,KAAK,GAAG;GAChB,KAAK,IAAI,OAAO,IAAI,GAAG,OAAO,KAAK,CAAC;GACpC,OAAO;EACT;EAEF,OAAO;CACT;CACA,KAAK,MAAM,QAAQ,OACjB,IAAI,MAAM,IAAI,GAAG,OAAO;CAE1B,OAAO;AACT;AAQA,SAAS,eAAkB,OAAY,aAA0C;CAC/E,IAAI,QAAQ;CACZ,MAAM,QAAQ,CAAC,GAAG,KAAK;CAEvB,OAAO,MAAM,SAAS,GAAG;EAEvB,M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T,8KACA,uBAAuB,SAAS,kCAClC;OAEA,UAAA,oBAAC,MAAD;QAAM,MAAM;QAAe,WAAU;OAAW,CAAA;MAC1C,CAAA,CACJ,EAAA,CAAA,CAED;;IAEJ;GAGN,CAAA,GAAA,UAAU,WAAW,IACnB,kBAAkB,OAEnB,oBAAC,OAAD;IAAK,MAAK;IAAO,cAAY;IAC1B,UAAA,UAAU,KAAK,SACd,8BAAC,UAAD;KACE,GAAI;KACJ,GAAK,iBAAiB,EAAE,UAAU,eAAe,IAAI,CAAC;KACtD,KAAK,UAAU,OAAO,IAAI;KAC1B,MAAM;KACN,WAAW;KACX,gBAAgB,aAAa;KAC7B,YAAY,eAAe,aAAa;KACvB;KACjB,iBAAiB,KAAK,SAAS,sBAAsB,YAAY;MAC/D,MAAM,YAAY,IAAI,IAAI,QAAQ,gBAAgB,YAAY,QAAQ,YAAY,CAAC,CAAC;MACpF,UAAU,IAAI,KAAK,IAAI;MACvB,OAAO;OAAE,aAAa;OAAW;OAAW,MAAM;MAAM;KAC1D,CAAC;KACD,aAAa;IACd,CAAA,CACF;GACE,CAAA,CAEJ;;CACF,CAAA;AAET"}
|
|
1
|
+
{"version":3,"file":"Tree.js","names":["_Fragment"],"sources":["../../src/data/Tree.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, useState, type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { Icon } from \"./Icon\";\nimport { UiClose, UiCollapseAll, UiExpandAll, UiSearch } from \"../icons\";\nimport { TreeNode, type TreeKey, type TreeNodeProps } from \"./TreeNode\";\n\nexport type TreeProps<T> = Omit<\n TreeNodeProps<T>,\n \"node\" | \"depth\" | \"expandAll\" | \"forcedOpenKeys\" | \"revealPath\" | \"revealOverrides\" | \"onRevealToggle\"\n> & {\n /** Root nodes to render. */\n roots: T[];\n /** Empty-state content when no roots are provided. */\n empty?: ReactNode;\n /** Classes applied to the tree root. */\n className?: string;\n /** Accessible name applied to the tree root. */\n ariaLabel?: string;\n /**\n * Render the Expand all / Collapse all toolbar above the tree. Enabled by\n * default. Set to false to suppress when the tree is tiny or the controls\n * are owned externally.\n */\n showControls?: boolean;\n /**\n * Search box visibility. Omitted: shown for trees with more than 20 edges or\n * a `searchQuery`. `true`: always shown. `false`: never shown — a parent that\n * owns the filter input still filters through `searchQuery`.\n */\n showSearch?: boolean;\n /** Placeholder and accessible name of the search box, e.g. \"Filter tests\". */\n searchLabel?: string;\n /** URL or parent-controlled search query. */\n searchQuery?: string;\n onSearchQueryChange?: (query: string) => void;\n /**\n * Externally controlled expand-all state. When provided together with\n * `onExpandAllChange`, the tree is controlled; otherwise it manages the\n * toolbar state internally.\n */\n expandAll?: boolean | null;\n /** Called when the toolbar expand-all state changes. */\n onExpandAllChange?: (next: boolean | null) => void;\n /** Classes applied to the search/control toolbar. */\n toolbarClassName?: string;\n /**\n * Extra controls rendered in the toolbar's right-hand group, before Expand\n * all / Collapse all. Providing actions shows the toolbar even when the tree\n * is too small for the filter and `showControls` is off.\n */\n actions?: ReactNode;\n /**\n * Override the text the filter matches against for a given node.\n * Defaults to a recursive walk of the node's own fields (excluding\n * its `children` and any secondary children), which works for\n * plain-shape trees but leaks text from nested domain objects —\n * e.g. a SQL Table's Field rows are marked secondary, yet the\n * parent record still carries `record.fields[].field` strings that\n * the default walker would collect. Callers that need precise\n * control over search behaviour should return only the text they\n * want surfaced (the node's own display label / id / type).\n */\n getSearchText?: (node: T) => string;\n /**\n * Reveal only the path to `selected` when it changes from outside the tree\n * (initial mount or navigation). Ancestors initially show the next path node;\n * manual expansion and collapse then take precedence until the next external\n * selection. Selecting a row by clicking it never re-reveals. Off by default.\n */\n revealSelected?: boolean;\n};\n\nfunction selectionPath<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n targetKey: TreeKey,\n): Map<TreeKey, TreeKey | null> | null {\n const path = new Map<TreeKey, TreeKey | null>();\n const visit = (node: T): boolean => {\n if (getKey(node) === targetKey) {\n path.set(targetKey, null);\n return true;\n }\n for (const child of getChildren(node) ?? []) {\n if (visit(child)) {\n path.set(getKey(node), getKey(child));\n return true;\n }\n }\n return false;\n };\n for (const root of roots) {\n if (visit(root)) return path;\n }\n return null;\n}\n\n// Edge counting, search-text collection and filtering all walk the tree through\n// the synchronous `getChildren` only. A lazy node (one declared via\n// `hasMoreChildren` whose children have not been fetched yet) therefore\n// contributes no edges and no search text until the operator expands it — so it\n// is invisible to \"expand all\" and to the filter while still collapsed. This is\n// intentional: we never trigger network loads from bulk/search operations.\nfunction countTreeEdges<T>(roots: T[], getChildren: TreeProps<T>[\"getChildren\"]) {\n let total = 0;\n const stack = [...roots];\n\n while (stack.length > 0) {\n const node = stack.pop()!;\n const children = getChildren(node) ?? [];\n total += children.length;\n stack.push(...children);\n }\n\n return total;\n}\n\nfunction collectTreeSearchText(\n value: unknown,\n excluded = new Set<unknown>(),\n seen = new Set<unknown>(),\n): string {\n if (value == null || excluded.has(value)) return \"\";\n\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\"\n ) {\n return String(value);\n }\n\n if (typeof value !== \"object\") return \"\";\n if (seen.has(value)) return \"\";\n seen.add(value);\n\n if (Array.isArray(value)) {\n return value\n .map((entry) => collectTreeSearchText(entry, excluded, seen))\n .filter(Boolean)\n .join(\" \");\n }\n\n const preferredKeys = [\"label\", \"name\", \"title\", \"text\", \"plain\", \"id\", \"content\"];\n const record = value as Record<string, unknown>;\n const chunks: string[] = [];\n\n for (const key of preferredKeys) {\n if (!(key in record)) continue;\n const text = collectTreeSearchText(record[key], excluded, seen);\n if (text) chunks.push(text);\n }\n\n for (const [key, entry] of Object.entries(record)) {\n if (key === \"children\" || preferredKeys.includes(key)) continue;\n const text = collectTreeSearchText(entry, excluded, seen);\n if (text) chunks.push(text);\n }\n\n return chunks.join(\" \");\n}\n\nfunction nodeSearchText<T>(node: T, children: ReturnType<TreeProps<T>[\"getChildren\"]>) {\n const excluded = new Set<unknown>();\n if (children) excluded.add(children);\n return collectTreeSearchText(node, excluded).trim().toLowerCase();\n}\n\nfunction filterTreeRoots<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n query: string,\n isSecondary?: (node: T) => boolean,\n getSearchText?: (node: T) => string,\n) {\n const normalizedQuery = query.trim().toLowerCase();\n if (!normalizedQuery) {\n return {\n roots,\n filteredChildren: null as Map<string | number, T[]> | null,\n forcedOpenKeys: null as Set<string | number> | null,\n };\n }\n\n const filteredChildren = new Map<string | number, T[]>();\n const forcedOpenKeys = new Set<string | number>();\n\n function matchText(node: T, children: T[]): string {\n // Honour the caller-supplied text extractor first — it's the\n // only way to get precise control over what the filter sees when\n // the node carries domain data whose fields would otherwise leak\n // into the default walker.\n if (getSearchText) return getSearchText(node).trim().toLowerCase();\n // Match-text skips secondary children so e.g. a Table's search\n // text only draws from the Table itself, not from its Field\n // rows. The Table is primary, so its own text still counts.\n const searchChildren = children.filter((c) => !isSecondary?.(c));\n return nodeSearchText(node, searchChildren);\n }\n\n function visit(node: T): boolean {\n // A secondary node never drives a filter match — it's\n // effectively invisible to search. Still rendered when the\n // caller opens the parent manually. This is what lets a 28k-row\n // field tree stay searchable at the record level without \"field\n // name contains 'x'\" matches spamming the results.\n if (isSecondary?.(node)) return false;\n\n const key = getKey(node);\n const children = getChildren(node) ?? [];\n const childrenAllSecondary =\n children.length > 0 && children.every((child) => isSecondary?.(child));\n const matches = matchText(node, children).includes(normalizedQuery);\n const visibleChildren: T[] = [];\n\n for (const child of children) {\n if (visit(child)) visibleChildren.push(child);\n }\n\n if (matches) {\n if (children.length > 0) {\n filteredChildren.set(key, children);\n if (!childrenAllSecondary) forcedOpenKeys.add(key);\n }\n return true;\n }\n\n if (visibleChildren.length > 0) {\n filteredChildren.set(key, visibleChildren);\n forcedOpenKeys.add(key);\n return true;\n }\n\n return false;\n }\n\n return {\n roots: roots.filter((root) => visit(root)),\n filteredChildren,\n forcedOpenKeys,\n };\n}\n\nexport function Tree<T>({\n roots,\n empty,\n className,\n ariaLabel,\n showControls = true,\n showSearch,\n searchLabel,\n searchQuery,\n onSearchQueryChange,\n expandAll: controlledExpandAll,\n onExpandAllChange,\n toolbarClassName,\n actions,\n getSearchText,\n revealSelected = false,\n ...nodeProps\n}: TreeProps<T>) {\n const [internalExpandAll, setInternalExpandAll] = useState<boolean | null>(null);\n const [internalFilterQuery, setInternalFilterQuery] = useState(\"\");\n const filterQuery = searchQuery ?? internalFilterQuery;\n const setFilterQuery = (next: string) => {\n if (searchQuery !== undefined) onSearchQueryChange?.(next);\n else setInternalFilterQuery(next);\n };\n const basePaddingPx = nodeProps.basePaddingPx ?? 8;\n const isControlled = onExpandAllChange !== undefined;\n const expandAll = isControlled ? (controlledExpandAll ?? null) : internalExpandAll;\n const selectedKey = revealSelected && nodeProps.selected != null ? nodeProps.getKey(nodeProps.selected) : null;\n // revealKey drives the path reveal; it follows selectedKey except when the\n // selection came from clicking a row in this tree.\n const [reveal, setReveal] = useState({ selectedKey, revealKey: selectedKey, clickedKey: null as TreeKey | null });\n const [revealInteraction, setRevealInteraction] = useState({\n selectedKey: null as TreeKey | null,\n overrides: new Map<TreeKey, boolean>(),\n bulk: false,\n });\n if (reveal.selectedKey !== selectedKey) {\n const fromTree = selectedKey !== null && selectedKey === reveal.clickedKey;\n setReveal({ selectedKey, revealKey: fromTree ? reveal.revealKey : selectedKey, clickedKey: null });\n // An external selection is a fresh reveal: toggles and bulk controls made\n // for an earlier visit to the same key no longer apply.\n if (!fromTree) setRevealInteraction({ selectedKey: null, overrides: new Map(), bulk: false });\n }\n const revealKey = reveal.revealKey;\n const previousExpandAll = useRef(expandAll);\n useEffect(() => {\n if (previousExpandAll.current === expandAll) return;\n previousExpandAll.current = expandAll;\n setRevealInteraction({ selectedKey: revealKey, overrides: new Map(), bulk: true });\n }, [expandAll, revealKey]);\n const totalEdges = useMemo(\n () => countTreeEdges(roots, nodeProps.getChildren),\n [roots, nodeProps.getChildren],\n );\n const showFilter = showSearch ?? (totalEdges > 20 || Boolean(searchQuery));\n const activeFilter = showFilter || showSearch === false ? filterQuery : \"\";\n const filteredTree = useMemo(\n () =>\n filterTreeRoots(\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ),\n [\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ],\n );\n const treeRoots = filteredTree.roots;\n const filteredChildren = filteredTree.filteredChildren;\n const revealPath = useMemo(\n () =>\n revealSelected && revealKey !== null\n ? selectionPath(roots, nodeProps.getChildren, nodeProps.getKey, revealKey)\n : null,\n [revealSelected, roots, nodeProps.getChildren, nodeProps.getKey, revealKey],\n );\n const activeReveal = !activeFilter.trim() && !(revealInteraction.selectedKey === revealKey && revealInteraction.bulk);\n const revealOverrides = revealInteraction.selectedKey === revealKey ? revealInteraction.overrides : null;\n const onSelect = nodeProps.onSelect;\n const selectFromTree = onSelect\n ? (node: T) => {\n setReveal((current) => ({ ...current, clickedKey: nodeProps.getKey(node) }));\n onSelect(node);\n }\n : undefined;\n const effectiveGetChildren = filteredChildren\n ? (node: T) => filteredChildren.get(nodeProps.getKey(node)) ?? []\n : nodeProps.getChildren;\n const effectiveExpandAll = expandAll;\n const effectiveEmpty = activeFilter.trim() ? (\n <div className=\"px-3 py-4 text-sm text-muted-foreground\">No matching tree nodes.</div>\n ) : (\n empty\n );\n const showControlButtons = showControls && roots.length > 0;\n const showVirtualRow = showFilter || showControlButtons || actions != null;\n const setExpandAll = (next: boolean | null) => {\n setRevealInteraction({ selectedKey: revealKey, overrides: new Map(), bulk: true });\n if (isControlled) onExpandAllChange?.(next);\n else setInternalExpandAll(next);\n };\n\n if (treeRoots.length === 0 && !showVirtualRow) return <>{effectiveEmpty ?? null}</>;\n\n return (\n <div className={cn(\"flex flex-col min-h-0\", className)}>\n <div className=\"min-h-0 flex-1 overflow-auto\">\n {showVirtualRow && (\n <div\n role=\"presentation\"\n className={cn(\n \"sticky top-0 z-10 flex items-center gap-1.5 border-b border-border/70 bg-background/95 py-1 pr-2 text-sm backdrop-blur supports-[backdrop-filter]:bg-background/80\",\n toolbarClassName,\n )}\n style={{ paddingLeft: `${basePaddingPx}px` }}\n >\n {showFilter ? (\n <Icon icon={UiSearch} className=\"w-3 shrink-0 text-xs text-muted-foreground\" />\n ) : (\n <span className=\"w-3 shrink-0\" aria-hidden />\n )}\n\n {showFilter ? (\n <label className=\"flex min-w-0 flex-1 items-center gap-2 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground shadow-sm\">\n <input\n type=\"search\"\n value={filterQuery}\n onChange={(event) => setFilterQuery(event.target.value)}\n placeholder={searchLabel ?? \"Filter tree\"}\n className=\"h-5 w-full min-w-0 border-0 bg-transparent p-0 text-xs outline-none placeholder:text-placeholder [&::-webkit-search-cancel-button]:appearance-none\"\n aria-label={searchLabel ?? \"Filter tree nodes\"}\n />\n {filterQuery && (\n <button\n type=\"button\"\n onClick={() => setFilterQuery(\"\")}\n className=\"inline-flex items-center rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground\"\n aria-label=\"Clear tree filter\"\n title=\"Clear tree filter\"\n >\n <Icon icon={UiClose} className=\"text-xs\" />\n </button>\n )}\n </label>\n ) : (\n <span className=\"flex-1\" />\n )}\n\n {(showControlButtons || actions != null) && (\n <div className=\"ml-auto flex items-center gap-1\">\n {actions}\n {showControlButtons && (\n <>\n <button\n type=\"button\"\n onClick={() => setExpandAll(true)}\n aria-pressed={effectiveExpandAll === true}\n aria-label=\"Expand all\"\n title=\"Expand all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === true && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiExpandAll} className=\"text-sm\" />\n </button>\n <button\n type=\"button\"\n onClick={() => setExpandAll(false)}\n aria-pressed={effectiveExpandAll === false}\n aria-label=\"Collapse all\"\n title=\"Collapse all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === false && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiCollapseAll} className=\"text-sm\" />\n </button>\n </>\n )}\n </div>\n )}\n </div>\n )}\n\n {treeRoots.length === 0 ? (\n (effectiveEmpty ?? null)\n ) : (\n <div role=\"tree\" aria-label={ariaLabel}>\n {treeRoots.map((root) => (\n <TreeNode<T>\n {...nodeProps}\n {...(selectFromTree ? { onSelect: selectFromTree } : {})}\n key={nodeProps.getKey(root)}\n node={root}\n expandAll={effectiveExpandAll}\n forcedOpenKeys={filteredTree.forcedOpenKeys}\n revealPath={activeReveal ? revealPath : null}\n revealOverrides={revealOverrides}\n onRevealToggle={(key, open) => setRevealInteraction((current) => {\n const overrides = new Map(current.selectedKey === revealKey ? current.overrides : []);\n overrides.set(key, open);\n return { selectedKey: revealKey, overrides, bulk: false };\n })}\n getChildren={effectiveGetChildren}\n />\n ))}\n </div>\n )}\n </div>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAwEA,SAAS,cACP,OACA,aACA,QACA,WACqC;CACrC,MAAM,uBAAO,IAAI,IAA6B;CAC9C,MAAM,SAAS,SAAqB;EAClC,IAAI,OAAO,IAAI,MAAM,WAAW;GAC9B,KAAK,IAAI,WAAW,IAAI;GACxB,OAAO;EACT;EACA,KAAK,MAAM,SAAS,YAAY,IAAI,KAAK,CAAC,GACxC,IAAI,MAAM,KAAK,GAAG;GAChB,KAAK,IAAI,OAAO,IAAI,GAAG,OAAO,KAAK,CAAC;GACpC,OAAO;EACT;EAEF,OAAO;CACT;CACA,KAAK,MAAM,QAAQ,OACjB,IAAI,MAAM,IA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KAAK,CAAC,CAAC,SAAS;OACvC,WAAW,GACT,8KACA,uBAAuB,QAAQ,kCACjC;OAEA,UAAA,oBAAC,MAAD;QAAM,MAAM;QAAa,WAAU;OAAW,CAAA;MACxC,CAAA,GACR,oBAAC,UAAD;OACE,MAAK;OACL,eAAe,aAAa,KAAK;OACjC,gBAAc,uBAAuB;OACrC,cAAW;OACX,OAAM;OACN,UAAU,aAAa,KAAK,CAAC,CAAC,SAAS;OACvC,WAAW,GACT,8KACA,uBAAuB,SAAS,kCAClC;OAEA,UAAA,oBAAC,MAAD;QAAM,MAAM;QAAe,WAAU;OAAW,CAAA;MAC1C,CAAA,CACJ,EAAA,CAAA,CAED;;IAEJ;GAGN,CAAA,GAAA,UAAU,WAAW,IACnB,kBAAkB,OAEnB,oBAAC,OAAD;IAAK,MAAK;IAAO,cAAY;IAC1B,UAAA,UAAU,KAAK,SACd,8BAAC,UAAD;KACE,GAAI;KACJ,GAAK,iBAAiB,EAAE,UAAU,eAAe,IAAI,CAAC;KACtD,KAAK,UAAU,OAAO,IAAI;KAC1B,MAAM;KACN,WAAW;KACX,gBAAgB,aAAa;KAC7B,YAAY,eAAe,aAAa;KACvB;KACjB,iBAAiB,KAAK,SAAS,sBAAsB,YAAY;MAC/D,MAAM,YAAY,IAAI,IAAI,QAAQ,gBAAgB,YAAY,QAAQ,YAAY,CAAC,CAAC;MACpF,UAAU,IAAI,KAAK,IAAI;MACvB,OAAO;OAAE,aAAa;OAAW;OAAW,MAAM;MAAM;KAC1D,CAAC;KACD,aAAa;IACd,CAAA,CACF;GACE,CAAA,CAEJ;;CACF,CAAA;AAET"}
|
package/dist/data/TreeNode.cjs
CHANGED
|
@@ -6,16 +6,22 @@ let react = require("react");
|
|
|
6
6
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
7
|
// src/data/TreeNode.tsx
|
|
8
8
|
var ROW_CONTENT_OFFSET_PX = 18;
|
|
9
|
-
function
|
|
9
|
+
function mergeChildrenByKey(loaded, sync, getKey) {
|
|
10
|
+
if (!sync?.length) return loaded;
|
|
11
|
+
const current = new Map(sync.map((child) => [getKey(child), child]));
|
|
12
|
+
const loadedKeys = new Set(loaded.map(getKey));
|
|
13
|
+
return [...loaded.map((child) => current.get(getKey(child)) ?? child), ...sync.filter((child) => !loadedKeys.has(getKey(child)))];
|
|
14
|
+
}
|
|
15
|
+
function TreeNode({ node, depth = 0, expandAll = null, forcedOpenKeys = null, revealPath = null, revealOverrides = null, onRevealToggle, selected = null, defaultOpen, getExpanded, onExpandedChange, getChildren, getKey, getAriaLabel, onSelect, renderRow, renderDetail, renderAfterChildren, rowClass, indentPx = 16, basePaddingPx = 8, isSecondary, hasMoreChildren, loadChildren, reloadOnOpen = false, getChildrenVersion }) {
|
|
10
16
|
if (getExpanded && !onExpandedChange) throw new Error("Controlled tree expansion requires onExpandedChange");
|
|
11
17
|
const [loadedChildren, setLoadedChildren] = (0, react.useState)(null);
|
|
12
18
|
const [loading, setLoading] = (0, react.useState)(false);
|
|
13
19
|
const [error, setError] = (0, react.useState)(null);
|
|
14
20
|
const syncChildren = getChildren(node);
|
|
15
|
-
const children = loadedChildren
|
|
21
|
+
const children = loadedChildren === null ? syncChildren : mergeChildrenByKey(loadedChildren, syncChildren, getKey);
|
|
16
22
|
const hasChildren = (children?.length ?? 0) > 0;
|
|
17
23
|
const lazyUnloaded = (hasMoreChildren?.(node) ?? false) && loadedChildren === null;
|
|
18
|
-
const expandable = hasChildren || lazyUnloaded;
|
|
24
|
+
const expandable = hasChildren || lazyUnloaded || Boolean(reloadOnOpen && hasMoreChildren?.(node));
|
|
19
25
|
const secondaryNode = isSecondary?.(node) ?? false;
|
|
20
26
|
const childrenAllSecondary = hasChildren && isSecondary != null && children.every((c) => isSecondary(c));
|
|
21
27
|
const skipExpandAll = secondaryNode || childrenAllSecondary || expandAll === true && lazyUnloaded;
|
|
@@ -28,8 +34,8 @@ function TreeNode({ node, depth = 0, expandAll = null, forcedOpenKeys = null, re
|
|
|
28
34
|
const revealNextKey = revealPath?.get(key) ?? null;
|
|
29
35
|
const isOnRevealPath = revealNextKey !== null;
|
|
30
36
|
const revealOverride = revealOverrides?.get(key);
|
|
31
|
-
const pathOnly = isOnRevealPath && revealOverride === void 0;
|
|
32
37
|
const ownOpen = getExpanded ? getExpanded(node) : open;
|
|
38
|
+
const pathOnly = isOnRevealPath && revealOverride === void 0 && !ownOpen;
|
|
33
39
|
const isOpen = isForcedOpen || pathOnly || (revealOverride ?? ownOpen);
|
|
34
40
|
(0, react.useEffect)(() => {
|
|
35
41
|
if (expandAll !== null && expandAll !== prevExpandAll.current && !skipExpandAll) {
|
|
@@ -47,18 +53,22 @@ function TreeNode({ node, depth = 0, expandAll = null, forcedOpenKeys = null, re
|
|
|
47
53
|
const loadRequested = (0, react.useRef)(false);
|
|
48
54
|
const nodeKey = getKey(node);
|
|
49
55
|
const loadKeyRef = (0, react.useRef)(nodeKey);
|
|
56
|
+
const loadGeneration = (0, react.useRef)(0);
|
|
57
|
+
const childrenVersion = getChildrenVersion?.(node);
|
|
58
|
+
const previousChildrenVersion = (0, react.useRef)(childrenVersion);
|
|
50
59
|
function loadLazyChildren() {
|
|
51
60
|
if (!loadChildren || loadRequested.current) return;
|
|
52
61
|
loadRequested.current = true;
|
|
62
|
+
const generation = ++loadGeneration.current;
|
|
53
63
|
loadKeyRef.current = nodeKey;
|
|
54
64
|
setLoading(true);
|
|
55
65
|
setError(null);
|
|
56
66
|
loadChildren(node).then((kids) => {
|
|
57
|
-
if (loadKeyRef.current !== nodeKey) return;
|
|
67
|
+
if (loadKeyRef.current !== nodeKey || generation !== loadGeneration.current) return;
|
|
58
68
|
setLoadedChildren(kids);
|
|
59
69
|
setLoading(false);
|
|
60
70
|
}).catch((err) => {
|
|
61
|
-
if (loadKeyRef.current !== nodeKey) return;
|
|
71
|
+
if (loadKeyRef.current !== nodeKey || generation !== loadGeneration.current) return;
|
|
62
72
|
loadRequested.current = false;
|
|
63
73
|
setError(err);
|
|
64
74
|
setLoading(false);
|
|
@@ -71,17 +81,28 @@ function TreeNode({ node, depth = 0, expandAll = null, forcedOpenKeys = null, re
|
|
|
71
81
|
lazyUnloaded,
|
|
72
82
|
error
|
|
73
83
|
]);
|
|
84
|
+
(0, react.useEffect)(() => {
|
|
85
|
+
if (!getChildrenVersion || previousChildrenVersion.current === childrenVersion) return;
|
|
86
|
+
previousChildrenVersion.current = childrenVersion;
|
|
87
|
+
loadRequested.current = false;
|
|
88
|
+
if (isOpen && hasMoreChildren?.(node)) loadLazyChildren();
|
|
89
|
+
}, [childrenVersion]);
|
|
90
|
+
(0, react.useEffect)(() => () => {
|
|
91
|
+
loadGeneration.current++;
|
|
92
|
+
loadRequested.current = false;
|
|
93
|
+
}, []);
|
|
74
94
|
function toggle() {
|
|
75
95
|
if (!expandable) return;
|
|
76
96
|
if (isOnRevealPath) {
|
|
77
97
|
if (!onRevealToggle) throw new Error("A revealed tree path requires onRevealToggle");
|
|
78
|
-
const next = pathOnly || !revealOverride;
|
|
98
|
+
const next = pathOnly || !(revealOverride ?? ownOpen);
|
|
79
99
|
if (next && lazyUnloaded) loadLazyChildren();
|
|
80
100
|
onRevealToggle(key, next);
|
|
81
101
|
return;
|
|
82
102
|
}
|
|
83
103
|
const next = !ownOpen;
|
|
84
|
-
if (next &&
|
|
104
|
+
if (next && reloadOnOpen && hasMoreChildren?.(node)) loadRequested.current = false;
|
|
105
|
+
if (next && (lazyUnloaded || reloadOnOpen)) loadLazyChildren();
|
|
85
106
|
if (getExpanded) onExpandedChange(node, next);
|
|
86
107
|
else setOpen(next);
|
|
87
108
|
}
|
|
@@ -161,7 +182,9 @@ function TreeNode({ node, depth = 0, expandAll = null, forcedOpenKeys = null, re
|
|
|
161
182
|
...rowClass ? { rowClass } : {},
|
|
162
183
|
...isSecondary ? { isSecondary } : {},
|
|
163
184
|
...hasMoreChildren ? { hasMoreChildren } : {},
|
|
164
|
-
...loadChildren ? { loadChildren } : {}
|
|
185
|
+
...loadChildren ? { loadChildren } : {},
|
|
186
|
+
reloadOnOpen,
|
|
187
|
+
...getChildrenVersion ? { getChildrenVersion } : {}
|
|
165
188
|
}, getKey(child)))
|
|
166
189
|
}),
|
|
167
190
|
afterChildren != null && afterChildren !== false && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|