@flanksource/clicky-ui 0.3.60 → 0.3.62
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 +14 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-anchor.cjs","names":[],"sources":["../../../src/comments/anchoring/markdown-anchor.ts"],"sourcesContent":["/**\n * Comment anchors on rendered markdown. A markdown document has a structure\n * that a CSS path ignores: its outline. A comment here is keyed on the block it\n * was left on — named by the headings above it (its table-of-contents path)\n * and its text — so editing other parts of the file never moves it, and a\n * reworded block is still found within its section.\n */\nimport {\n COMMENT_LOCATOR_TEXT_LIMIT,\n type CommentLocator,\n} from \"./model\";\n\nexport type MarkdownLocator = Extract<CommentLocator, { kind: \"markdown\" }>;\n\n/** Rendered markdown whose top-level blocks carry `data-source-start` (Markdown `sourceBlocks`). */\nexport const MARKDOWN_ROOT = \"[data-annotated-markdown]\";\nconst SOURCE_BLOCK = \"[data-source-start]\";\n/** Parts of a top-level block that are commented on by themselves. */\nconst SUB_BLOCK = \"li,tr\";\nconst HEADING = /^h([1-6])$/;\nconst ANCHOR_PREFIX = \"md:\";\n/** Share of words a reworded block must keep to be taken for the original. */\nexport const MARKDOWN_SIMILARITY_THRESHOLD = 0.6;\nconst MAX_LABEL_TEXT = 60;\n\nfunction normalizeText(text: string | null): string {\n return (text ?? \"\").replace(/\\s+/g, \" \").trim();\n}\n\nfunction blockText(element: Element): string {\n return normalizeText(element.textContent).slice(0, COMMENT_LOCATOR_TEXT_LIMIT);\n}\n\ntype OutlineEntry = { block: Element; path: string[]; line: number };\n\n/** Every top-level block of `root` in document order, with the heading path it sits under. */\nfunction outline(root: Element): OutlineEntry[] {\n const stack: { level: number; text: string }[] = [];\n return [...root.querySelectorAll(SOURCE_BLOCK)]\n .filter((block) => !block.parentElement?.closest(SOURCE_BLOCK))\n .map((block) => {\n const level = HEADING.exec(block.tagName.toLowerCase())?.[1];\n if (level) {\n while (stack.length > 0 && (stack.at(-1)?.level ?? 0) >= Number(level)) stack.pop();\n stack.push({ level: Number(level), text: blockText(block) });\n }\n return {\n block,\n path: stack.map((heading) => heading.text),\n line: Number((block as HTMLElement).dataset.sourceStart),\n };\n });\n}\n\ntype Candidate = { element: Element; path: string[]; line: number };\n\nfunction candidates(root: Element): Candidate[] {\n return outline(root).flatMap(({ block, path, line }) => [\n { element: block, path, line },\n ...[...block.querySelectorAll(SUB_BLOCK)].map((element) => ({ element, path, line })),\n ]);\n}\n\nfunction samePath(a: readonly string[], b: readonly string[]): boolean {\n return a.length === b.length && a.every((text, index) => text === b[index]);\n}\n\n/**\n * The block a click inside rendered markdown comments on: the list item or\n * table row it is in, else its top-level block. A block without text (a rule,\n * an image) yields its section heading, since text is what finds it again.\n * Null outside rendered markdown or outside every block.\n */\nexport function markdownTarget(target: Element): { root: Element; block: Element } | null {\n const root = target.closest(MARKDOWN_ROOT);\n const top = target.closest(SOURCE_BLOCK);\n if (!root || !top || !root.contains(top)) return null;\n const sub = target.closest(SUB_BLOCK);\n const block = sub && top.contains(sub) ? sub : top;\n if (blockText(block) !== \"\") return { root, block };\n const entries = outline(root);\n const index = entries.findIndex((entry) => entry.block === top || entry.block.contains(top));\n const heading = entries\n .slice(0, index + 1)\n .reverse()\n .find((entry) => HEADING.test(entry.block.tagName.toLowerCase()));\n return heading ? { root, block: heading.block } : null;\n}\n\n/** The locator describing a block `markdownTarget` returned. */\nexport function markdownLocator(block: Element, root: Element): MarkdownLocator {\n const found = candidates(root).find((candidate) => candidate.element === block);\n if (!found) throw new Error(\"markdownLocator: the block is not part of the rendered markdown\");\n return {\n kind: \"markdown\",\n path: found.path,\n tag: block.tagName.toLowerCase(),\n text: blockText(block),\n ...(Number.isInteger(found.line) && found.line > 0 ? { line: found.line } : {}),\n };\n}\n\n/** The anchor for a markdown block: its locator without the line, so later comments on the block share it. */\nexport function markdownAnchor(locator: MarkdownLocator): string {\n return `${ANCHOR_PREFIX}${JSON.stringify([locator.path, locator.tag, locator.text])}`;\n}\n\n/** The locator a markdown anchor encodes, or null for any other anchor. */\nexport function parseMarkdownAnchor(anchor: string): MarkdownLocator | null {\n if (!anchor.startsWith(ANCHOR_PREFIX)) return null;\n const parsed: unknown = JSON.parse(anchor.slice(ANCHOR_PREFIX.length));\n const [path, tag, text] = Array.isArray(parsed) ? parsed : [];\n if (\n !Array.isArray(path) ||\n !path.every((heading) => typeof heading === \"string\") ||\n typeof tag !== \"string\" ||\n typeof text !== \"string\"\n ) {\n throw new Error(`malformed markdown comment anchor ${JSON.stringify(anchor)}`);\n }\n return { kind: \"markdown\", path, tag, text };\n}\n\nfunction words(text: string): Set<string> {\n return new Set(text.toLowerCase().match(/[\\p{L}\\p{N}]+/gu) ?? []);\n}\n\nfunction similarity(a: string, b: string): number {\n const left = words(a);\n const right = words(b);\n const shared = [...left].filter((word) => right.has(word)).length;\n const union = left.size + right.size - shared;\n return union === 0 ? 0 : shared / union;\n}\n\n/** The one candidate, or the one nearest the captured line when several match. */\nfunction nearest(found: Candidate[], line: number | undefined): Element | null {\n if (found.length <= 1) return found[0]?.element ?? null;\n if (line === undefined) return null;\n const distance = (candidate: Candidate) => Math.abs(candidate.line - line);\n const sorted = [...found].sort((a, b) => distance(a) - distance(b));\n const [first, second] = sorted;\n return first && second && distance(first) === distance(second) ? null : (first?.element ?? null);\n}\n\nexport type MarkdownResolution = {\n element: Element;\n /** How the block was found: unchanged in its section, reworded in it, or by text elsewhere. */\n how: \"exact\" | \"edited\" | \"relocated\";\n};\n\n/**\n * Finds a commented block again: by its text within its section, then the\n * section's most similar block of the same kind, then its text anywhere.\n */\nexport function resolveMarkdown(root: Element, locator: MarkdownLocator): MarkdownResolution | null {\n const all = candidates(root).filter((candidate) => candidate.element.tagName.toLowerCase() === locator.tag);\n const section = all.filter((candidate) => samePath(candidate.path, locator.path));\n const sameText = (candidate: Candidate) => blockText(candidate.element) === locator.text;\n\n const exact = nearest(section.filter(sameText), locator.line);\n if (exact) return { element: exact, how: \"exact\" };\n\n const scored = section\n .map((candidate) => ({ candidate, score: similarity(blockText(candidate.element), locator.text) }))\n .filter(({ score }) => score >= MARKDOWN_SIMILARITY_THRESHOLD)\n .sort((a, b) => b.score - a.score);\n const [best, runnerUp] = scored;\n if (best && best.score !== runnerUp?.score) return { element: best.candidate.element, how: \"edited\" };\n\n const relocated = nearest(all.filter(sameText), locator.line);\n return relocated ? { element: relocated, how: \"relocated\" } : null;\n}\n\nconst BLOCK_NAMES: Record<string, string> = {\n p: \"paragraph\",\n li: \"list item\",\n ul: \"list\",\n ol: \"list\",\n tr: \"table row\",\n blockquote: \"quote\",\n div: \"block\",\n pre: \"code\",\n};\n\n/** Reader-facing description of a markdown block: its section, its kind and its opening words. */\nexport function describeMarkdown(locator: Pick<MarkdownLocator, \"path\" | \"tag\" | \"text\">): string {\n const heading = HEADING.test(locator.tag);\n const kind = heading ? \"heading\" : (BLOCK_NAMES[locator.tag] ?? locator.tag);\n // A heading is the last entry of its own path.\n const path = heading ? locator.path.slice(0, -1) : locator.path;\n const text =\n locator.text.length > MAX_LABEL_TEXT ? `${locator.text.slice(0, MAX_LABEL_TEXT)}…` : locator.text;\n const section = path.length > 0 ? `${path.join(\" › \")} — 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AS,iBAAiB,GAAG,QAAQ,KAAK,MAAM,GAAG,cAAc,EAAE,KAAK,QAAQ;CAE/F,OAAO,GADS,KAAK,SAAS,IAAI,GAAG,KAAK,KAAK,KAAK,EAAE,OAAO,KACzC,KAAK,IAAI,KAAK;AACpC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { CommentLocator } from './model.js';
|
|
2
|
+
export type MarkdownLocator = Extract<CommentLocator, {
|
|
3
|
+
kind: "markdown";
|
|
4
|
+
}>;
|
|
5
|
+
/** Rendered markdown whose top-level blocks carry `data-source-start` (Markdown `sourceBlocks`). */
|
|
6
|
+
export declare const MARKDOWN_ROOT = "[data-annotated-markdown]";
|
|
7
|
+
/** Share of words a reworded block must keep to be taken for the original. */
|
|
8
|
+
export declare const MARKDOWN_SIMILARITY_THRESHOLD = 0.6;
|
|
9
|
+
/**
|
|
10
|
+
* The block a click inside rendered markdown comments on: the list item or
|
|
11
|
+
* table row it is in, else its top-level block. A block without text (a rule,
|
|
12
|
+
* an image) yields its section heading, since text is what finds it again.
|
|
13
|
+
* Null outside rendered markdown or outside every block.
|
|
14
|
+
*/
|
|
15
|
+
export declare function markdownTarget(target: Element): {
|
|
16
|
+
root: Element;
|
|
17
|
+
block: Element;
|
|
18
|
+
} | null;
|
|
19
|
+
/** The locator describing a block `markdownTarget` returned. */
|
|
20
|
+
export declare function markdownLocator(block: Element, root: Element): MarkdownLocator;
|
|
21
|
+
/** The anchor for a markdown block: its locator without the line, so later comments on the block share it. */
|
|
22
|
+
export declare function markdownAnchor(locator: MarkdownLocator): string;
|
|
23
|
+
/** The locator a markdown anchor encodes, or null for any other anchor. */
|
|
24
|
+
export declare function parseMarkdownAnchor(anchor: string): MarkdownLocator | null;
|
|
25
|
+
export type MarkdownResolution = {
|
|
26
|
+
element: Element;
|
|
27
|
+
/** How the block was found: unchanged in its section, reworded in it, or by text elsewhere. */
|
|
28
|
+
how: "exact" | "edited" | "relocated";
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Finds a commented block again: by its text within its section, then the
|
|
32
|
+
* section's most similar block of the same kind, then its text anywhere.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveMarkdown(root: Element, locator: MarkdownLocator): MarkdownResolution | null;
|
|
35
|
+
/** Reader-facing description of a markdown block: its section, its kind and its opening words. */
|
|
36
|
+
export declare function describeMarkdown(locator: Pick<MarkdownLocator, "path" | "tag" | "text">): string;
|
|
37
|
+
//# sourceMappingURL=markdown-anchor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-anchor.d.ts","sourceRoot":"","sources":["../../../src/comments/anchoring/markdown-anchor.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,SAAS,CAAC;AAEjB,MAAM,MAAM,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC;AAE5E,oGAAoG;AACpG,eAAO,MAAM,aAAa,8BAA8B,CAAC;AAMzD,8EAA8E;AAC9E,eAAO,MAAM,6BAA6B,MAAM,CAAC;AA6CjD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAcxF;AAED,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,eAAe,CAU9E;AAED,8GAA8G;AAC9G,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAE/D;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAa1E;AAwBD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,+FAA+F;IAC/F,GAAG,EAAE,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAC;CACvC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,kBAAkB,GAAG,IAAI,CAiBlG;AAaD,kGAAkG;AAClG,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC,GAAG,MAAM,CAShG"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import "./model.js";
|
|
2
|
+
// src/comments/anchoring/markdown-anchor.ts
|
|
3
|
+
/**
|
|
4
|
+
* Comment anchors on rendered markdown. A markdown document has a structure
|
|
5
|
+
* that a CSS path ignores: its outline. A comment here is keyed on the block it
|
|
6
|
+
* was left on — named by the headings above it (its table-of-contents path)
|
|
7
|
+
* and its text — so editing other parts of the file never moves it, and a
|
|
8
|
+
* reworded block is still found within its section.
|
|
9
|
+
*/
|
|
10
|
+
/** Rendered markdown whose top-level blocks carry `data-source-start` (Markdown `sourceBlocks`). */
|
|
11
|
+
var MARKDOWN_ROOT = "[data-annotated-markdown]";
|
|
12
|
+
var SOURCE_BLOCK = "[data-source-start]";
|
|
13
|
+
/** Parts of a top-level block that are commented on by themselves. */
|
|
14
|
+
var SUB_BLOCK = "li,tr";
|
|
15
|
+
var HEADING = /^h([1-6])$/;
|
|
16
|
+
var ANCHOR_PREFIX = "md:";
|
|
17
|
+
/** Share of words a reworded block must keep to be taken for the original. */
|
|
18
|
+
var MARKDOWN_SIMILARITY_THRESHOLD = .6;
|
|
19
|
+
var MAX_LABEL_TEXT = 60;
|
|
20
|
+
function normalizeText(text) {
|
|
21
|
+
return (text ?? "").replace(/\s+/g, " ").trim();
|
|
22
|
+
}
|
|
23
|
+
function blockText(element) {
|
|
24
|
+
return normalizeText(element.textContent).slice(0, 200);
|
|
25
|
+
}
|
|
26
|
+
/** Every top-level block of `root` in document order, with the heading path it sits under. */
|
|
27
|
+
function outline(root) {
|
|
28
|
+
const stack = [];
|
|
29
|
+
return [...root.querySelectorAll(SOURCE_BLOCK)].filter((block) => !block.parentElement?.closest(SOURCE_BLOCK)).map((block) => {
|
|
30
|
+
const level = HEADING.exec(block.tagName.toLowerCase())?.[1];
|
|
31
|
+
if (level) {
|
|
32
|
+
while (stack.length > 0 && (stack.at(-1)?.level ?? 0) >= Number(level)) stack.pop();
|
|
33
|
+
stack.push({
|
|
34
|
+
level: Number(level),
|
|
35
|
+
text: blockText(block)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
block,
|
|
40
|
+
path: stack.map((heading) => heading.text),
|
|
41
|
+
line: Number(block.dataset.sourceStart)
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function candidates(root) {
|
|
46
|
+
return outline(root).flatMap(({ block, path, line }) => [{
|
|
47
|
+
element: block,
|
|
48
|
+
path,
|
|
49
|
+
line
|
|
50
|
+
}, ...[...block.querySelectorAll(SUB_BLOCK)].map((element) => ({
|
|
51
|
+
element,
|
|
52
|
+
path,
|
|
53
|
+
line
|
|
54
|
+
}))]);
|
|
55
|
+
}
|
|
56
|
+
function samePath(a, b) {
|
|
57
|
+
return a.length === b.length && a.every((text, index) => text === b[index]);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The block a click inside rendered markdown comments on: the list item or
|
|
61
|
+
* table row it is in, else its top-level block. A block without text (a rule,
|
|
62
|
+
* an image) yields its section heading, since text is what finds it again.
|
|
63
|
+
* Null outside rendered markdown or outside every block.
|
|
64
|
+
*/
|
|
65
|
+
function markdownTarget(target) {
|
|
66
|
+
const root = target.closest(MARKDOWN_ROOT);
|
|
67
|
+
const top = target.closest(SOURCE_BLOCK);
|
|
68
|
+
if (!root || !top || !root.contains(top)) return null;
|
|
69
|
+
const sub = target.closest(SUB_BLOCK);
|
|
70
|
+
const block = sub && top.contains(sub) ? sub : top;
|
|
71
|
+
if (blockText(block) !== "") return {
|
|
72
|
+
root,
|
|
73
|
+
block
|
|
74
|
+
};
|
|
75
|
+
const entries = outline(root);
|
|
76
|
+
const index = entries.findIndex((entry) => entry.block === top || entry.block.contains(top));
|
|
77
|
+
const heading = entries.slice(0, index + 1).reverse().find((entry) => HEADING.test(entry.block.tagName.toLowerCase()));
|
|
78
|
+
return heading ? {
|
|
79
|
+
root,
|
|
80
|
+
block: heading.block
|
|
81
|
+
} : null;
|
|
82
|
+
}
|
|
83
|
+
/** The locator describing a block `markdownTarget` returned. */
|
|
84
|
+
function markdownLocator(block, root) {
|
|
85
|
+
const found = candidates(root).find((candidate) => candidate.element === block);
|
|
86
|
+
if (!found) throw new Error("markdownLocator: the block is not part of the rendered markdown");
|
|
87
|
+
return {
|
|
88
|
+
kind: "markdown",
|
|
89
|
+
path: found.path,
|
|
90
|
+
tag: block.tagName.toLowerCase(),
|
|
91
|
+
text: blockText(block),
|
|
92
|
+
...Number.isInteger(found.line) && found.line > 0 ? { line: found.line } : {}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** The anchor for a markdown block: its locator without the line, so later comments on the block share it. */
|
|
96
|
+
function markdownAnchor(locator) {
|
|
97
|
+
return `${ANCHOR_PREFIX}${JSON.stringify([
|
|
98
|
+
locator.path,
|
|
99
|
+
locator.tag,
|
|
100
|
+
locator.text
|
|
101
|
+
])}`;
|
|
102
|
+
}
|
|
103
|
+
/** The locator a markdown anchor encodes, or null for any other anchor. */
|
|
104
|
+
function parseMarkdownAnchor(anchor) {
|
|
105
|
+
if (!anchor.startsWith(ANCHOR_PREFIX)) return null;
|
|
106
|
+
const parsed = JSON.parse(anchor.slice(3));
|
|
107
|
+
const [path, tag, text] = Array.isArray(parsed) ? parsed : [];
|
|
108
|
+
if (!Array.isArray(path) || !path.every((heading) => typeof heading === "string") || typeof tag !== "string" || typeof text !== "string") throw new Error(`malformed markdown comment anchor ${JSON.stringify(anchor)}`);
|
|
109
|
+
return {
|
|
110
|
+
kind: "markdown",
|
|
111
|
+
path,
|
|
112
|
+
tag,
|
|
113
|
+
text
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function words(text) {
|
|
117
|
+
return new Set(text.toLowerCase().match(/[\p{L}\p{N}]+/gu) ?? []);
|
|
118
|
+
}
|
|
119
|
+
function similarity(a, b) {
|
|
120
|
+
const left = words(a);
|
|
121
|
+
const right = words(b);
|
|
122
|
+
const shared = [...left].filter((word) => right.has(word)).length;
|
|
123
|
+
const union = left.size + right.size - shared;
|
|
124
|
+
return union === 0 ? 0 : shared / union;
|
|
125
|
+
}
|
|
126
|
+
/** The one candidate, or the one nearest the captured line when several match. */
|
|
127
|
+
function nearest(found, line) {
|
|
128
|
+
if (found.length <= 1) return found[0]?.element ?? null;
|
|
129
|
+
if (line === void 0) return null;
|
|
130
|
+
const distance = (candidate) => Math.abs(candidate.line - line);
|
|
131
|
+
const [first, second] = [...found].sort((a, b) => distance(a) - distance(b));
|
|
132
|
+
return first && second && distance(first) === distance(second) ? null : first?.element ?? null;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Finds a commented block again: by its text within its section, then the
|
|
136
|
+
* section's most similar block of the same kind, then its text anywhere.
|
|
137
|
+
*/
|
|
138
|
+
function resolveMarkdown(root, locator) {
|
|
139
|
+
const all = candidates(root).filter((candidate) => candidate.element.tagName.toLowerCase() === locator.tag);
|
|
140
|
+
const section = all.filter((candidate) => samePath(candidate.path, locator.path));
|
|
141
|
+
const sameText = (candidate) => blockText(candidate.element) === locator.text;
|
|
142
|
+
const exact = nearest(section.filter(sameText), locator.line);
|
|
143
|
+
if (exact) return {
|
|
144
|
+
element: exact,
|
|
145
|
+
how: "exact"
|
|
146
|
+
};
|
|
147
|
+
const [best, runnerUp] = section.map((candidate) => ({
|
|
148
|
+
candidate,
|
|
149
|
+
score: similarity(blockText(candidate.element), locator.text)
|
|
150
|
+
})).filter(({ score }) => score >= MARKDOWN_SIMILARITY_THRESHOLD).sort((a, b) => b.score - a.score);
|
|
151
|
+
if (best && best.score !== runnerUp?.score) return {
|
|
152
|
+
element: best.candidate.element,
|
|
153
|
+
how: "edited"
|
|
154
|
+
};
|
|
155
|
+
const relocated = nearest(all.filter(sameText), locator.line);
|
|
156
|
+
return relocated ? {
|
|
157
|
+
element: relocated,
|
|
158
|
+
how: "relocated"
|
|
159
|
+
} : null;
|
|
160
|
+
}
|
|
161
|
+
var BLOCK_NAMES = {
|
|
162
|
+
p: "paragraph",
|
|
163
|
+
li: "list item",
|
|
164
|
+
ul: "list",
|
|
165
|
+
ol: "list",
|
|
166
|
+
tr: "table row",
|
|
167
|
+
blockquote: "quote",
|
|
168
|
+
div: "block",
|
|
169
|
+
pre: "code"
|
|
170
|
+
};
|
|
171
|
+
/** Reader-facing description of a markdown block: its section, its kind and its opening words. */
|
|
172
|
+
function describeMarkdown(locator) {
|
|
173
|
+
const heading = HEADING.test(locator.tag);
|
|
174
|
+
const kind = heading ? "heading" : BLOCK_NAMES[locator.tag] ?? locator.tag;
|
|
175
|
+
const path = heading ? locator.path.slice(0, -1) : locator.path;
|
|
176
|
+
const text = locator.text.length > MAX_LABEL_TEXT ? `${locator.text.slice(0, MAX_LABEL_TEXT)}…` : locator.text;
|
|
177
|
+
return `${path.length > 0 ? `${path.join(" › ")} — ` : ""}${kind} “${text}”`;
|
|
178
|
+
}
|
|
179
|
+
export { MARKDOWN_ROOT, MARKDOWN_SIMILARITY_THRESHOLD, describeMarkdown, markdownAnchor, markdownLocator, markdownTarget, parseMarkdownAnchor, resolveMarkdown };
|
|
180
|
+
|
|
181
|
+
//# sourceMappingURL=markdown-anchor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-anchor.js","names":[],"sources":["../../../src/comments/anchoring/markdown-anchor.ts"],"sourcesContent":["/**\n * Comment anchors on rendered markdown. A markdown document has a structure\n * that a CSS path ignores: its outline. A comment here is keyed on the block it\n * was left on — named by the headings above it (its table-of-contents path)\n * and its text — so editing other parts of the file never moves it, and a\n * reworded block is still found within its section.\n */\nimport {\n COMMENT_LOCATOR_TEXT_LIMIT,\n type CommentLocator,\n} from \"./model\";\n\nexport type MarkdownLocator = Extract<CommentLocator, { kind: \"markdown\" }>;\n\n/** Rendered markdown whose top-level blocks carry `data-source-start` (Markdown `sourceBlocks`). */\nexport const MARKDOWN_ROOT = \"[data-annotated-markdown]\";\nconst SOURCE_BLOCK = \"[data-source-start]\";\n/** Parts of a top-level block that are commented on by themselves. */\nconst SUB_BLOCK = \"li,tr\";\nconst HEADING = /^h([1-6])$/;\nconst ANCHOR_PREFIX = \"md:\";\n/** Share of words a reworded block must keep to be taken for the original. */\nexport const MARKDOWN_SIMILARITY_THRESHOLD = 0.6;\nconst MAX_LABEL_TEXT = 60;\n\nfunction normalizeText(text: string | null): string {\n return (text ?? \"\").replace(/\\s+/g, \" \").trim();\n}\n\nfunction blockText(element: Element): string {\n return normalizeText(element.textContent).slice(0, COMMENT_LOCATOR_TEXT_LIMIT);\n}\n\ntype OutlineEntry = { block: Element; path: string[]; line: number };\n\n/** Every top-level block of `root` in document order, with the heading path it sits under. */\nfunction outline(root: Element): OutlineEntry[] {\n const stack: { level: number; text: string }[] = [];\n return [...root.querySelectorAll(SOURCE_BLOCK)]\n .filter((block) => !block.parentElement?.closest(SOURCE_BLOCK))\n .map((block) => {\n const level = HEADING.exec(block.tagName.toLowerCase())?.[1];\n if (level) {\n while (stack.length > 0 && (stack.at(-1)?.level ?? 0) >= Number(level)) stack.pop();\n stack.push({ level: Number(level), text: blockText(block) });\n }\n return {\n block,\n path: stack.map((heading) => heading.text),\n line: Number((block as HTMLElement).dataset.sourceStart),\n };\n });\n}\n\ntype Candidate = { element: Element; path: string[]; line: number };\n\nfunction candidates(root: Element): Candidate[] {\n return outline(root).flatMap(({ block, path, line }) => [\n { element: block, path, line },\n ...[...block.querySelectorAll(SUB_BLOCK)].map((element) => ({ element, path, line })),\n ]);\n}\n\nfunction samePath(a: readonly string[], b: readonly string[]): boolean {\n return a.length === b.length && a.every((text, index) => text === b[index]);\n}\n\n/**\n * The block a click inside rendered markdown comments on: the list item or\n * table row it is in, else its top-level block. A block without text (a rule,\n * an image) yields its section heading, since text is what finds it again.\n * Null outside rendered markdown or outside every block.\n */\nexport function markdownTarget(target: Element): { root: Element; block: Element } | null {\n const root = target.closest(MARKDOWN_ROOT);\n const top = target.closest(SOURCE_BLOCK);\n if (!root || !top || !root.contains(top)) return null;\n const sub = target.closest(SUB_BLOCK);\n const block = sub && top.contains(sub) ? sub : top;\n if (blockText(block) !== \"\") return { root, block };\n const entries = outline(root);\n const index = entries.findIndex((entry) => entry.block === top || entry.block.contains(top));\n const heading = entries\n .slice(0, index + 1)\n .reverse()\n .find((entry) => HEADING.test(entry.block.tagName.toLowerCase()));\n return heading ? { root, block: heading.block } : null;\n}\n\n/** The locator describing a block `markdownTarget` returned. */\nexport function markdownLocator(block: Element, root: Element): MarkdownLocator {\n const found = candidates(root).find((candidate) => candidate.element === block);\n if (!found) throw new Error(\"markdownLocator: the block is not part of the rendered markdown\");\n return {\n kind: \"markdown\",\n path: found.path,\n tag: block.tagName.toLowerCase(),\n text: blockText(block),\n ...(Number.isInteger(found.line) && found.line > 0 ? { line: found.line } : {}),\n };\n}\n\n/** The anchor for a markdown block: its locator without the line, so later comments on the block share it. */\nexport function markdownAnchor(locator: MarkdownLocator): string {\n return `${ANCHOR_PREFIX}${JSON.stringify([locator.path, locator.tag, locator.text])}`;\n}\n\n/** The locator a markdown anchor encodes, or null for any other anchor. */\nexport function parseMarkdownAnchor(anchor: string): MarkdownLocator | null {\n if (!anchor.startsWith(ANCHOR_PREFIX)) return null;\n const parsed: unknown = JSON.parse(anchor.slice(ANCHOR_PREFIX.length));\n const [path, tag, text] = Array.isArray(parsed) ? parsed : [];\n if (\n !Array.isArray(path) ||\n !path.every((heading) => typeof heading === \"string\") ||\n typeof tag !== \"string\" ||\n typeof text !== \"string\"\n ) {\n throw new Error(`malformed markdown comment anchor ${JSON.stringify(anchor)}`);\n }\n return { kind: \"markdown\", path, tag, text };\n}\n\nfunction words(text: string): Set<string> {\n return new Set(text.toLowerCase().match(/[\\p{L}\\p{N}]+/gu) ?? []);\n}\n\nfunction similarity(a: string, b: string): number {\n const left = words(a);\n const right = words(b);\n const shared = [...left].filter((word) => right.has(word)).length;\n const union = left.size + right.size - shared;\n return union === 0 ? 0 : shared / union;\n}\n\n/** The one candidate, or the one nearest the captured line when several match. */\nfunction nearest(found: Candidate[], line: number | undefined): Element | null {\n if (found.length <= 1) return found[0]?.element ?? null;\n if (line === undefined) return null;\n const distance = (candidate: Candidate) => Math.abs(candidate.line - line);\n const sorted = [...found].sort((a, b) => distance(a) - distance(b));\n const [first, second] = sorted;\n return first && second && distance(first) === distance(second) ? null : (first?.element ?? null);\n}\n\nexport type MarkdownResolution = {\n element: Element;\n /** How the block was found: unchanged in its section, reworded in it, or by text elsewhere. */\n how: \"exact\" | \"edited\" | \"relocated\";\n};\n\n/**\n * Finds a commented block again: by its text within its section, then the\n * section's most similar block of the same kind, then its text anywhere.\n */\nexport function resolveMarkdown(root: Element, locator: MarkdownLocator): MarkdownResolution | null {\n const all = candidates(root).filter((candidate) => candidate.element.tagName.toLowerCase() === locator.tag);\n const section = all.filter((candidate) => samePath(candidate.path, locator.path));\n const sameText = (candidate: Candidate) => blockText(candidate.element) === locator.text;\n\n const exact = nearest(section.filter(sameText), locator.line);\n if (exact) return { element: exact, how: \"exact\" };\n\n const scored = section\n .map((candidate) => ({ candidate, score: similarity(blockText(candidate.element), locator.text) }))\n .filter(({ score }) => score >= MARKDOWN_SIMILARITY_THRESHOLD)\n .sort((a, b) => b.score - a.score);\n const [best, runnerUp] = scored;\n if (best && best.score !== runnerUp?.score) return { element: best.candidate.element, how: \"edited\" };\n\n const relocated = nearest(all.filter(sameText), locator.line);\n return relocated ? { element: relocated, how: \"relocated\" } : null;\n}\n\nconst BLOCK_NAMES: Record<string, string> = {\n p: \"paragraph\",\n li: \"list item\",\n ul: \"list\",\n ol: \"list\",\n tr: \"table row\",\n blockquote: \"quote\",\n div: \"block\",\n pre: \"code\",\n};\n\n/** Reader-facing description of a markdown block: its section, its kind and its opening words. */\nexport function describeMarkdown(locator: Pick<MarkdownLocator, \"path\" | \"tag\" | \"text\">): string {\n const heading = HEADING.test(locator.tag);\n const kind = heading ? \"heading\" : (BLOCK_NAMES[locator.tag] ?? locator.tag);\n // A heading is the last entry of its own path.\n const path = heading ? locator.path.slice(0, -1) : locator.path;\n const text =\n locator.text.length > MAX_LABEL_TEXT ? `${locator.text.slice(0, MAX_LABEL_TEXT)}…` : locator.text;\n const section = path.length > 0 ? `${path.join(\" › \")} — ` : \"\";\n return `${section}${kind} “${text}”`;\n}\n"],"mappings":";;;;;;;;;;AAeA,IAAa,gBAAgB;AAC7B,IAAM,eAAe;;AAErB,IAAM,YAAY;AAClB,IAAM,UAAU;AAChB,IAAM,gBAAgB;;AAEtB,IAAa,gCAAgC;AAC7C,IAAM,iBAAiB;AAEvB,SAAS,cAAc,MAA6B;CAClD,QAAQ,QAAQ,GAAA,CAAI,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;AAChD;AAEA,SAAS,UAAU,SAA0B;CAC3C,OAAO,cAAc,QAAQ,WAAW,CAAC,CAAC,MAAM,GAAA,GAA6B;AAC/E;;AAKA,SAAS,QAAQ,MAA+B;CAC9C,MAAM,QAA2C,CAAC;CAClD,OAAO,CAAC,GAAG,KAAK,iBAAiB,YAAY,CAAC,CAAC,CAC5C,QAAQ,UAAU,CAAC,MAAM,eAAe,QAAQ,YAAY,CAAC,CAAC,CAC9D,KAAK,UAAU;EACd,MAAM,QAAQ,QAAQ,KAAK,MAAM,QAAQ,YAAY,CAAC,CAAC,GAAG;EAC1D,IAAI,OAAO;GACT,OAAO,MAAM,SAAS,MAAM,MAAM,GAAG,EAAE,CAAC,EAAE,SAAS,MAAM,OAAO,KAAK,GAAG,MAAM,IAAI;GAClF,MAAM,KAAK;IAAE,OAAO,OAAO,KAAK;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,OAAO,YAAY;EAAE,SAAS;EAAW,KAAK;CAAY,IAAI;AAChE;AAEA,IAAM,cAAsC;CAC1C,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,YAAY;CACZ,KAAK;CACL,KAAK;AACP;;AAGA,SAAgB,iBAAiB,SAAiE;CAChG,MAAM,UAAU,QAAQ,KAAK,QAAQ,GAAG;CACxC,MAAM,OAAO,UAAU,YAAa,YAAY,QAAQ,QAAQ,QAAQ;CAExE,MAAM,OAAO,UAAU,QAAQ,KAAK,MAAM,GAAG,EAAE,IAAI,QAAQ;CAC3D,MAAM,OACJ,QAAQ,KAAK,SAAS,iBAAiB,GAAG,QAAQ,KAAK,MAAM,GAAG,cAAc,EAAE,KAAK,QAAQ;CAE/F,OAAO,GADS,KAAK,SAAS,IAAI,GAAG,KAAK,KAAK,KAAK,EAAE,OAAO,KACzC,KAAK,IAAI,KAAK;AACpC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/comments/anchoring/model.ts
|
|
2
|
+
var COMMENT_ELEMENT_HTML_LIMIT = 4096;
|
|
3
|
+
var COMMENT_ELEMENT_HTML_TRUNCATION = "\n<!-- …truncated to 4KB -->";
|
|
4
|
+
var COMMENT_LOCATOR_TEXT_LIMIT = 200;
|
|
5
|
+
var COMMENT_LOCATOR_SELECTOR_LIMIT = 1024;
|
|
6
|
+
exports.COMMENT_ELEMENT_HTML_LIMIT = COMMENT_ELEMENT_HTML_LIMIT;
|
|
7
|
+
exports.COMMENT_ELEMENT_HTML_TRUNCATION = COMMENT_ELEMENT_HTML_TRUNCATION;
|
|
8
|
+
exports.COMMENT_LOCATOR_SELECTOR_LIMIT = COMMENT_LOCATOR_SELECTOR_LIMIT;
|
|
9
|
+
exports.COMMENT_LOCATOR_TEXT_LIMIT = COMMENT_LOCATOR_TEXT_LIMIT;
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=model.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.cjs","names":[],"sources":["../../../src/comments/anchoring/model.ts"],"sourcesContent":["export const COMMENT_ELEMENT_HTML_LIMIT = 4096;\nexport const COMMENT_ELEMENT_HTML_TRUNCATION = \"\\n<!-- …truncated to 4KB -->\";\nexport const COMMENT_LOCATOR_TEXT_LIMIT = 200;\nexport const COMMENT_LOCATOR_SELECTOR_LIMIT = 1024;\n\nexport type CommentLocatorHeading = { selector: string; text: string };\nexport type CommentLocator =\n | { kind: \"css\"; selector: string }\n | { kind: \"role\"; tag: string; role: string; name: string }\n | { kind: \"text\"; tag: string; text: string; heading?: CommentLocatorHeading; scope?: string }\n | { kind: \"markdown\"; path: string[]; tag: string; text: string; line?: number };\n"],"mappings":";AAAA,IAAa,6BAA6B;AAC1C,IAAa,kCAAkC;AAC/C,IAAa,6BAA6B;AAC1C,IAAa,iCAAiC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare const COMMENT_ELEMENT_HTML_LIMIT = 4096;
|
|
2
|
+
export declare const COMMENT_ELEMENT_HTML_TRUNCATION = "\n<!-- \u2026truncated to 4KB -->";
|
|
3
|
+
export declare const COMMENT_LOCATOR_TEXT_LIMIT = 200;
|
|
4
|
+
export declare const COMMENT_LOCATOR_SELECTOR_LIMIT = 1024;
|
|
5
|
+
export type CommentLocatorHeading = {
|
|
6
|
+
selector: string;
|
|
7
|
+
text: string;
|
|
8
|
+
};
|
|
9
|
+
export type CommentLocator = {
|
|
10
|
+
kind: "css";
|
|
11
|
+
selector: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: "role";
|
|
14
|
+
tag: string;
|
|
15
|
+
role: string;
|
|
16
|
+
name: string;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "text";
|
|
19
|
+
tag: string;
|
|
20
|
+
text: string;
|
|
21
|
+
heading?: CommentLocatorHeading;
|
|
22
|
+
scope?: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "markdown";
|
|
25
|
+
path: string[];
|
|
26
|
+
tag: string;
|
|
27
|
+
text: string;
|
|
28
|
+
line?: number;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/comments/anchoring/model.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAC/C,eAAO,MAAM,+BAA+B,sCAAiC,CAAC;AAC9E,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAC9C,eAAO,MAAM,8BAA8B,OAAO,CAAC;AAEnD,MAAM,MAAM,qBAAqB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AACvE,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,qBAAqB,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5F;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// src/comments/anchoring/model.ts
|
|
2
|
+
var COMMENT_ELEMENT_HTML_LIMIT = 4096;
|
|
3
|
+
var COMMENT_ELEMENT_HTML_TRUNCATION = "\n<!-- …truncated to 4KB -->";
|
|
4
|
+
var COMMENT_LOCATOR_TEXT_LIMIT = 200;
|
|
5
|
+
var COMMENT_LOCATOR_SELECTOR_LIMIT = 1024;
|
|
6
|
+
export { COMMENT_ELEMENT_HTML_LIMIT, COMMENT_ELEMENT_HTML_TRUNCATION, COMMENT_LOCATOR_SELECTOR_LIMIT, COMMENT_LOCATOR_TEXT_LIMIT };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","names":[],"sources":["../../../src/comments/anchoring/model.ts"],"sourcesContent":["export const COMMENT_ELEMENT_HTML_LIMIT = 4096;\nexport const COMMENT_ELEMENT_HTML_TRUNCATION = \"\\n<!-- …truncated to 4KB -->\";\nexport const COMMENT_LOCATOR_TEXT_LIMIT = 200;\nexport const COMMENT_LOCATOR_SELECTOR_LIMIT = 1024;\n\nexport type CommentLocatorHeading = { selector: string; text: string };\nexport type CommentLocator =\n | { kind: \"css\"; selector: string }\n | { kind: \"role\"; tag: string; role: string; name: string }\n | { kind: \"text\"; tag: string; text: string; heading?: CommentLocatorHeading; scope?: string }\n | { kind: \"markdown\"; path: string[]; tag: string; text: string; line?: number };\n"],"mappings":";AAAA,IAAa,6BAA6B;AAC1C,IAAa,kCAAkC;AAC/C,IAAa,6BAA6B;AAC1C,IAAa,iCAAiC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// src/comments/anchoring/patch-anchor.ts
|
|
2
|
+
var PATCH_PREFIX = "r:";
|
|
3
|
+
/** Context lines kept on each side of the range. */
|
|
4
|
+
var CONTEXT_LINES = 3;
|
|
5
|
+
var splitLines = (source) => source.replaceAll("\r\n", "\n").split("\n");
|
|
6
|
+
/** The 1-based, inclusive lines `startLine`..`endLine` of `source` with their surrounding context. */
|
|
7
|
+
function capturePatch(source, startLine, endLine) {
|
|
8
|
+
const lines = splitLines(source);
|
|
9
|
+
if (startLine < 1 || endLine < startLine || endLine > lines.length) throw new Error("Source selection is outside the file");
|
|
10
|
+
return {
|
|
11
|
+
version: 1,
|
|
12
|
+
startLine,
|
|
13
|
+
endLine,
|
|
14
|
+
before: lines.slice(Math.max(0, startLine - 1 - CONTEXT_LINES), startLine - 1),
|
|
15
|
+
lines: lines.slice(startLine - 1, endLine),
|
|
16
|
+
after: lines.slice(endLine, endLine + CONTEXT_LINES)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
var isStringList = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
20
|
+
function assertPatch(value) {
|
|
21
|
+
const patch = value;
|
|
22
|
+
if (!(typeof patch === "object" && patch !== null && typeof patch.version === "number" && typeof patch.startLine === "number" && typeof patch.endLine === "number" && isStringList(patch.before) && isStringList(patch.lines) && isStringList(patch.after))) throw new Error("patch anchor is not a patch: expected {version, startLine, endLine, before, lines, after}");
|
|
23
|
+
}
|
|
24
|
+
function isPatchAnchor(anchor) {
|
|
25
|
+
return anchor.startsWith("r:");
|
|
26
|
+
}
|
|
27
|
+
function patchAnchor(patch) {
|
|
28
|
+
return `r:${JSON.stringify(patch)}`;
|
|
29
|
+
}
|
|
30
|
+
/** The patch an `r:` anchor holds; throws for any other anchor or malformed JSON. */
|
|
31
|
+
function parsePatchAnchor(anchor) {
|
|
32
|
+
if (!isPatchAnchor(anchor)) throw new Error(`expected an "r:" patch anchor, got ${JSON.stringify(anchor.slice(0, 40))}`);
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = JSON.parse(anchor.slice(2));
|
|
36
|
+
} catch (cause) {
|
|
37
|
+
throw new Error(`patch anchor is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
38
|
+
}
|
|
39
|
+
assertPatch(parsed);
|
|
40
|
+
return parsed;
|
|
41
|
+
}
|
|
42
|
+
/** Reader-facing label of the lines a patch was captured on. */
|
|
43
|
+
function describePatch(patch) {
|
|
44
|
+
return patch.startLine === patch.endLine ? `Line ${patch.startLine}` : `Lines ${patch.startLine}–${patch.endLine}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Where `patch` sits in `source` now. The whole hunk (before + lines + after)
|
|
48
|
+
* must match exactly: at the recorded position first, else at the one place it
|
|
49
|
+
* occurs in the file. More than one place is "ambiguous", none is "outdated".
|
|
50
|
+
*/
|
|
51
|
+
function matchPatch(source, patch) {
|
|
52
|
+
if (!(patch.version === 1 && patch.lines.length > 0 && patch.startLine >= 1 && patch.endLine - patch.startLine + 1 === patch.lines.length && patch.before.length <= CONTEXT_LINES && patch.after.length <= CONTEXT_LINES)) return { state: "outdated" };
|
|
53
|
+
const lines = splitLines(source);
|
|
54
|
+
const hunk = [
|
|
55
|
+
...patch.before,
|
|
56
|
+
...patch.lines,
|
|
57
|
+
...patch.after
|
|
58
|
+
];
|
|
59
|
+
const matchesAt = (index) => index >= 0 && index + hunk.length <= lines.length && hunk.every((line, i) => lines[index + i] === line);
|
|
60
|
+
const located = (index) => {
|
|
61
|
+
const startLine = index + patch.before.length + 1;
|
|
62
|
+
return {
|
|
63
|
+
state: "matched",
|
|
64
|
+
startLine,
|
|
65
|
+
endLine: startLine + patch.lines.length - 1
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const expected = patch.startLine - 1 - patch.before.length;
|
|
69
|
+
if (matchesAt(expected)) return located(expected);
|
|
70
|
+
let found = -1;
|
|
71
|
+
for (let index = 0; index + hunk.length <= lines.length; index++) {
|
|
72
|
+
if (!matchesAt(index)) continue;
|
|
73
|
+
if (found >= 0) return { state: "ambiguous" };
|
|
74
|
+
found = index;
|
|
75
|
+
}
|
|
76
|
+
return found >= 0 ? located(found) : { state: "outdated" };
|
|
77
|
+
}
|
|
78
|
+
exports.PATCH_PREFIX = PATCH_PREFIX;
|
|
79
|
+
exports.capturePatch = capturePatch;
|
|
80
|
+
exports.describePatch = describePatch;
|
|
81
|
+
exports.isPatchAnchor = isPatchAnchor;
|
|
82
|
+
exports.matchPatch = matchPatch;
|
|
83
|
+
exports.parsePatchAnchor = parsePatchAnchor;
|
|
84
|
+
exports.patchAnchor = patchAnchor;
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=patch-anchor.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-anchor.cjs","names":[],"sources":["../../../src/comments/anchoring/patch-anchor.ts"],"sourcesContent":["/**\n * Git-hunk anchors for line ranges: `r:` + JSON of a `PatchAnchor`.\n *\n * `capturePatch` and `matchPatch` are ports of gavel's `comments.CapturePatch`\n * and `comments.ResolvePatch` (comments/patch_anchor.go) and must stay\n * byte-for-byte compatible with them, so a client and the server place a\n * thread on the same lines. There is deliberately no fuzzy fallback: a hunk\n * that no longer matches exactly is \"outdated\", never silently moved.\n */\nimport type { PatchAnchor } from \"../annotation-types\";\n\nexport const PATCH_PREFIX = \"r:\";\n/** Context lines kept on each side of the range. */\nconst CONTEXT_LINES = 3;\n\nexport type PatchMatch =\n | { state: \"matched\"; startLine: number; endLine: number }\n | { state: \"ambiguous\" }\n | { state: \"outdated\" };\n\nconst splitLines = (source: string): string[] => source.replaceAll(\"\\r\\n\", \"\\n\").split(\"\\n\");\n\n/** The 1-based, inclusive lines `startLine`..`endLine` of `source` with their surrounding context. */\nexport function capturePatch(source: string, startLine: number, endLine: number): PatchAnchor {\n const lines = splitLines(source);\n if (startLine < 1 || endLine < startLine || endLine > lines.length) throw new Error(\"Source selection is outside the file\");\n return {\n version: 1,\n startLine,\n endLine,\n before: lines.slice(Math.max(0, startLine - 1 - CONTEXT_LINES), startLine - 1),\n lines: lines.slice(startLine - 1, endLine),\n after: lines.slice(endLine, endLine + CONTEXT_LINES),\n };\n}\n\nconst isStringList = (value: unknown): value is string[] => Array.isArray(value) && value.every((item) => typeof item === \"string\");\n\nfunction assertPatch(value: unknown): asserts value is PatchAnchor {\n const patch = value as Partial<Record<keyof PatchAnchor, unknown>> | null;\n const ok =\n typeof patch === \"object\" &&\n patch !== null &&\n typeof patch.version === \"number\" &&\n typeof patch.startLine === \"number\" &&\n typeof patch.endLine === \"number\" &&\n isStringList(patch.before) &&\n isStringList(patch.lines) &&\n isStringList(patch.after);\n if (!ok) throw new Error(\"patch anchor is not a patch: expected {version, startLine, endLine, before, lines, after}\");\n}\n\nexport function isPatchAnchor(anchor: string): boolean {\n return anchor.startsWith(PATCH_PREFIX);\n}\n\nexport function patchAnchor(patch: PatchAnchor): string {\n return `${PATCH_PREFIX}${JSON.stringify(patch)}`;\n}\n\n/** The patch an `r:` anchor holds; throws for any other anchor or malformed JSON. */\nexport function parsePatchAnchor(anchor: string): PatchAnchor {\n if (!isPatchAnchor(anchor)) throw new Error(`expected an \"r:\" patch anchor, got ${JSON.stringify(anchor.slice(0, 40))}`);\n let parsed: unknown;\n try {\n parsed = JSON.parse(anchor.slice(PATCH_PREFIX.length));\n } catch (cause) {\n throw new Error(`patch anchor is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`);\n }\n assertPatch(parsed);\n return parsed;\n}\n\n/** Reader-facing label of the lines a patch was captured on. */\nexport function describePatch(patch: PatchAnchor): string {\n return patch.startLine === patch.endLine ? `Line ${patch.startLine}` : `Lines ${patch.startLine}–${patch.endLine}`;\n}\n\n/**\n * Where `patch` sits in `source` now. The whole hunk (before + lines + after)\n * must match exactly: at the recorded position first, else at the one place it\n * occurs in the file. More than one place is \"ambiguous\", none is \"outdated\".\n */\nexport function matchPatch(source: string, patch: PatchAnchor): PatchMatch {\n const valid =\n patch.version === 1 &&\n patch.lines.length > 0 &&\n patch.startLine >= 1 &&\n patch.endLine - patch.startLine + 1 === patch.lines.length &&\n patch.before.length <= CONTEXT_LINES &&\n patch.after.length <= CONTEXT_LINES;\n if (!valid) return { state: \"outdated\" };\n\n const lines = splitLines(source);\n const hunk = [...patch.before, ...patch.lines, ...patch.after];\n const matchesAt = (index: number) => index >= 0 && index + hunk.length <= lines.length && hunk.every((line, i) => lines[index + i] === line);\n const located = (index: number): PatchMatch => {\n const startLine = index + patch.before.length + 1;\n return { state: \"matched\", startLine, endLine: startLine + patch.lines.length - 1 };\n };\n\n const expected = patch.startLine - 1 - patch.before.length;\n if (matchesAt(expected)) return located(expected);\n let found = -1;\n for (let index = 0; index + hunk.length <= lines.length; index++) {\n if (!matchesAt(index)) continue;\n if (found >= 0) return { state: \"ambiguous\" };\n found = index;\n }\n return found >= 0 ? located(found) : { state: \"outdated\" };\n}\n"],"mappings":";AAWA,IAAa,eAAe;;AAE5B,IAAM,gBAAgB;AAOtB,IAAM,cAAc,WAA6B,OAAO,WAAW,QAAQ,IAAI,CAAC,CAAC,MAAM,IAAI;;AAG3F,SAAgB,aAAa,QAAgB,WAAmB,SAA8B;CAC5F,MAAM,QAAQ,WAAW,MAAM;CAC/B,IAAI,YAAY,KAAK,UAAU,aAAa,UAAU,MAAM,QAAQ,MAAM,IAAI,MAAM,sCAAsC;CAC1H,OAAO;EACL,SAAS;EACT;EACA;EACA,QAAQ,MAAM,MAAM,KAAK,IAAI,GAAG,YAAY,IAAI,aAAa,GAAG,YAAY,CAAC;EAC7E,OAAO,MAAM,MAAM,YAAY,GAAG,OAAO;EACzC,OAAO,MAAM,MAAM,SAAS,UAAU,aAAa;CACrD;AACF;AAEA,IAAM,gBAAgB,UAAsC,MAAM,QAAQ,KAAK,KAAK,MAAM,OAAO,SAAS,OAAO,SAAS,QAAQ;AAElI,SAAS,YAAY,OAA8C;CACjE,MAAM,QAAQ;CAUd,IAAI,EARF,OAAO,UAAU,YACjB,UAAU,QACV,OAAO,MAAM,YAAY,YACzB,OAAO,MAAM,cAAc,YAC3B,OAAO,MAAM,YAAY,YACzB,aAAa,MAAM,MAAM,KACzB,aAAa,MAAM,KAAK,KACxB,aAAa,MAAM,KAAK,IACjB,MAAM,IAAI,MAAM,2FAA2F;AACtH;AAEA,SAAgB,cAAc,QAAyB;CACrD,OAAO,OAAO,WAAA,IAAuB;AACvC;AAEA,SAAgB,YAAY,OAA4B;CACtD,OAAO,KAAkB,KAAK,UAAU,KAAK;AAC/C;;AAGA,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AG,QAAQ,KAAK,UAAU,MAAM,QAAQ,SAAS;EAChE,IAAI,CAAC,UAAU,KAAK,GAAG;EACvB,IAAI,SAAS,GAAG,OAAO,EAAE,OAAO,YAAY;EAC5C,QAAQ;CACV;CACA,OAAO,SAAS,IAAI,QAAQ,KAAK,IAAI,EAAE,OAAO,WAAW;AAC3D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PatchAnchor } from '../annotation-types.js';
|
|
2
|
+
export declare const PATCH_PREFIX = "r:";
|
|
3
|
+
export type PatchMatch = {
|
|
4
|
+
state: "matched";
|
|
5
|
+
startLine: number;
|
|
6
|
+
endLine: number;
|
|
7
|
+
} | {
|
|
8
|
+
state: "ambiguous";
|
|
9
|
+
} | {
|
|
10
|
+
state: "outdated";
|
|
11
|
+
};
|
|
12
|
+
/** The 1-based, inclusive lines `startLine`..`endLine` of `source` with their surrounding context. */
|
|
13
|
+
export declare function capturePatch(source: string, startLine: number, endLine: number): PatchAnchor;
|
|
14
|
+
export declare function isPatchAnchor(anchor: string): boolean;
|
|
15
|
+
export declare function patchAnchor(patch: PatchAnchor): string;
|
|
16
|
+
/** The patch an `r:` anchor holds; throws for any other anchor or malformed JSON. */
|
|
17
|
+
export declare function parsePatchAnchor(anchor: string): PatchAnchor;
|
|
18
|
+
/** Reader-facing label of the lines a patch was captured on. */
|
|
19
|
+
export declare function describePatch(patch: PatchAnchor): string;
|
|
20
|
+
/**
|
|
21
|
+
* Where `patch` sits in `source` now. The whole hunk (before + lines + after)
|
|
22
|
+
* must match exactly: at the recorded position first, else at the one place it
|
|
23
|
+
* occurs in the file. More than one place is "ambiguous", none is "outdated".
|
|
24
|
+
*/
|
|
25
|
+
export declare function matchPatch(source: string, patch: PatchAnchor): PatchMatch;
|
|
26
|
+
//# sourceMappingURL=patch-anchor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-anchor.d.ts","sourceRoot":"","sources":["../../../src/comments/anchoring/patch-anchor.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,eAAO,MAAM,YAAY,OAAO,CAAC;AAIjC,MAAM,MAAM,UAAU,GAClB;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,KAAK,EAAE,WAAW,CAAA;CAAE,GACtB;IAAE,KAAK,EAAE,UAAU,CAAA;CAAE,CAAC;AAI1B,sGAAsG;AACtG,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,WAAW,CAW5F;AAkBD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAEtD;AAED,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAU5D;AAED,gEAAgE;AAChE,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAExD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,UAAU,CA2BzE"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/comments/anchoring/patch-anchor.ts
|
|
2
|
+
var PATCH_PREFIX = "r:";
|
|
3
|
+
/** Context lines kept on each side of the range. */
|
|
4
|
+
var CONTEXT_LINES = 3;
|
|
5
|
+
var splitLines = (source) => source.replaceAll("\r\n", "\n").split("\n");
|
|
6
|
+
/** The 1-based, inclusive lines `startLine`..`endLine` of `source` with their surrounding context. */
|
|
7
|
+
function capturePatch(source, startLine, endLine) {
|
|
8
|
+
const lines = splitLines(source);
|
|
9
|
+
if (startLine < 1 || endLine < startLine || endLine > lines.length) throw new Error("Source selection is outside the file");
|
|
10
|
+
return {
|
|
11
|
+
version: 1,
|
|
12
|
+
startLine,
|
|
13
|
+
endLine,
|
|
14
|
+
before: lines.slice(Math.max(0, startLine - 1 - CONTEXT_LINES), startLine - 1),
|
|
15
|
+
lines: lines.slice(startLine - 1, endLine),
|
|
16
|
+
after: lines.slice(endLine, endLine + CONTEXT_LINES)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
var isStringList = (value) => Array.isArray(value) && value.every((item) => typeof item === "string");
|
|
20
|
+
function assertPatch(value) {
|
|
21
|
+
const patch = value;
|
|
22
|
+
if (!(typeof patch === "object" && patch !== null && typeof patch.version === "number" && typeof patch.startLine === "number" && typeof patch.endLine === "number" && isStringList(patch.before) && isStringList(patch.lines) && isStringList(patch.after))) throw new Error("patch anchor is not a patch: expected {version, startLine, endLine, before, lines, after}");
|
|
23
|
+
}
|
|
24
|
+
function isPatchAnchor(anchor) {
|
|
25
|
+
return anchor.startsWith("r:");
|
|
26
|
+
}
|
|
27
|
+
function patchAnchor(patch) {
|
|
28
|
+
return `r:${JSON.stringify(patch)}`;
|
|
29
|
+
}
|
|
30
|
+
/** The patch an `r:` anchor holds; throws for any other anchor or malformed JSON. */
|
|
31
|
+
function parsePatchAnchor(anchor) {
|
|
32
|
+
if (!isPatchAnchor(anchor)) throw new Error(`expected an "r:" patch anchor, got ${JSON.stringify(anchor.slice(0, 40))}`);
|
|
33
|
+
let parsed;
|
|
34
|
+
try {
|
|
35
|
+
parsed = JSON.parse(anchor.slice(2));
|
|
36
|
+
} catch (cause) {
|
|
37
|
+
throw new Error(`patch anchor is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
38
|
+
}
|
|
39
|
+
assertPatch(parsed);
|
|
40
|
+
return parsed;
|
|
41
|
+
}
|
|
42
|
+
/** Reader-facing label of the lines a patch was captured on. */
|
|
43
|
+
function describePatch(patch) {
|
|
44
|
+
return patch.startLine === patch.endLine ? `Line ${patch.startLine}` : `Lines ${patch.startLine}–${patch.endLine}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Where `patch` sits in `source` now. The whole hunk (before + lines + after)
|
|
48
|
+
* must match exactly: at the recorded position first, else at the one place it
|
|
49
|
+
* occurs in the file. More than one place is "ambiguous", none is "outdated".
|
|
50
|
+
*/
|
|
51
|
+
function matchPatch(source, patch) {
|
|
52
|
+
if (!(patch.version === 1 && patch.lines.length > 0 && patch.startLine >= 1 && patch.endLine - patch.startLine + 1 === patch.lines.length && patch.before.length <= CONTEXT_LINES && patch.after.length <= CONTEXT_LINES)) return { state: "outdated" };
|
|
53
|
+
const lines = splitLines(source);
|
|
54
|
+
const hunk = [
|
|
55
|
+
...patch.before,
|
|
56
|
+
...patch.lines,
|
|
57
|
+
...patch.after
|
|
58
|
+
];
|
|
59
|
+
const matchesAt = (index) => index >= 0 && index + hunk.length <= lines.length && hunk.every((line, i) => lines[index + i] === line);
|
|
60
|
+
const located = (index) => {
|
|
61
|
+
const startLine = index + patch.before.length + 1;
|
|
62
|
+
return {
|
|
63
|
+
state: "matched",
|
|
64
|
+
startLine,
|
|
65
|
+
endLine: startLine + patch.lines.length - 1
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const expected = patch.startLine - 1 - patch.before.length;
|
|
69
|
+
if (matchesAt(expected)) return located(expected);
|
|
70
|
+
let found = -1;
|
|
71
|
+
for (let index = 0; index + hunk.length <= lines.length; index++) {
|
|
72
|
+
if (!matchesAt(index)) continue;
|
|
73
|
+
if (found >= 0) return { state: "ambiguous" };
|
|
74
|
+
found = index;
|
|
75
|
+
}
|
|
76
|
+
return found >= 0 ? located(found) : { state: "outdated" };
|
|
77
|
+
}
|
|
78
|
+
export { PATCH_PREFIX, capturePatch, describePatch, isPatchAnchor, matchPatch, parsePatchAnchor, patchAnchor };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=patch-anchor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patch-anchor.js","names":[],"sources":["../../../src/comments/anchoring/patch-anchor.ts"],"sourcesContent":["/**\n * Git-hunk anchors for line ranges: `r:` + JSON of a `PatchAnchor`.\n *\n * `capturePatch` and `matchPatch` are ports of gavel's `comments.CapturePatch`\n * and `comments.ResolvePatch` (comments/patch_anchor.go) and must stay\n * byte-for-byte compatible with them, so a client and the server place a\n * thread on the same lines. There is deliberately no fuzzy fallback: a hunk\n * that no longer matches exactly is \"outdated\", never silently moved.\n */\nimport type { PatchAnchor } from \"../annotation-types\";\n\nexport const PATCH_PREFIX = \"r:\";\n/** Context lines kept on each side of the range. */\nconst CONTEXT_LINES = 3;\n\nexport type PatchMatch =\n | { state: \"matched\"; startLine: number; endLine: number }\n | { state: \"ambiguous\" }\n | { state: \"outdated\" };\n\nconst splitLines = (source: string): string[] => source.replaceAll(\"\\r\\n\", \"\\n\").split(\"\\n\");\n\n/** The 1-based, inclusive lines `startLine`..`endLine` of `source` with their surrounding context. */\nexport function capturePatch(source: string, startLine: number, endLine: number): PatchAnchor {\n const lines = splitLines(source);\n if (startLine < 1 || endLine < startLine || endLine > lines.length) throw new Error(\"Source selection is outside the file\");\n return {\n version: 1,\n startLine,\n endLine,\n before: lines.slice(Math.max(0, startLine - 1 - CONTEXT_LINES), startLine - 1),\n lines: lines.slice(startLine - 1, endLine),\n after: lines.slice(endLine, endLine + CONTEXT_LINES),\n };\n}\n\nconst isStringList = (value: unknown): value is string[] => Array.isArray(value) && value.every((item) => typeof item === \"string\");\n\nfunction assertPatch(value: unknown): asserts value is PatchAnchor {\n const patch = value as Partial<Record<keyof PatchAnchor, unknown>> | null;\n const ok =\n typeof patch === \"object\" &&\n patch !== null &&\n typeof patch.version === \"number\" &&\n typeof patch.startLine === \"number\" &&\n typeof patch.endLine === \"number\" &&\n isStringList(patch.before) &&\n isStringList(patch.lines) &&\n isStringList(patch.after);\n if (!ok) throw new Error(\"patch anchor is not a patch: expected {version, startLine, endLine, before, lines, after}\");\n}\n\nexport function isPatchAnchor(anchor: string): boolean {\n return anchor.startsWith(PATCH_PREFIX);\n}\n\nexport function patchAnchor(patch: PatchAnchor): string {\n return `${PATCH_PREFIX}${JSON.stringify(patch)}`;\n}\n\n/** The patch an `r:` anchor holds; throws for any other anchor or malformed JSON. */\nexport function parsePatchAnchor(anchor: string): PatchAnchor {\n if (!isPatchAnchor(anchor)) throw new Error(`expected an \"r:\" patch anchor, got ${JSON.stringify(anchor.slice(0, 40))}`);\n let parsed: unknown;\n try {\n parsed = JSON.parse(anchor.slice(PATCH_PREFIX.length));\n } catch (cause) {\n throw new Error(`patch anchor is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`);\n }\n assertPatch(parsed);\n return parsed;\n}\n\n/** Reader-facing label of the lines a patch was captured on. */\nexport function describePatch(patch: PatchAnchor): string {\n return patch.startLine === patch.endLine ? `Line ${patch.startLine}` : `Lines ${patch.startLine}–${patch.endLine}`;\n}\n\n/**\n * Where `patch` sits in `source` now. The whole hunk (before + lines + after)\n * must match exactly: at the recorded position first, else at the one place it\n * occurs in the file. More than one place is \"ambiguous\", none is \"outdated\".\n */\nexport function matchPatch(source: string, patch: PatchAnchor): PatchMatch {\n const valid =\n patch.version === 1 &&\n patch.lines.length > 0 &&\n patch.startLine >= 1 &&\n patch.endLine - patch.startLine + 1 === patch.lines.length &&\n patch.before.length <= CONTEXT_LINES &&\n patch.after.length <= CONTEXT_LINES;\n if (!valid) return { state: \"outdated\" };\n\n const lines = splitLines(source);\n const hunk = [...patch.before, ...patch.lines, ...patch.after];\n const matchesAt = (index: number) => index >= 0 && index + hunk.length <= lines.length && hunk.every((line, i) => lines[index + i] === line);\n const located = (index: number): PatchMatch => {\n const startLine = index + patch.before.length + 1;\n return { state: \"matched\", startLine, endLine: startLine + patch.lines.length - 1 };\n };\n\n const expected = patch.startLine - 1 - patch.before.length;\n if (matchesAt(expected)) return located(expected);\n let found = -1;\n for (let index = 0; index + hunk.length <= lines.length; index++) {\n if (!matchesAt(index)) continue;\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