@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,384 @@
|
|
|
1
|
+
import "./model.js";
|
|
2
|
+
import { MARKDOWN_ROOT, markdownAnchor, markdownLocator, markdownTarget, parseMarkdownAnchor, resolveMarkdown } from "./markdown-anchor.js";
|
|
3
|
+
import { attr, finder } from "@medv/finder";
|
|
4
|
+
import { computeAccessibleName, getRole } from "dom-accessibility-api";
|
|
5
|
+
// src/comments/anchoring/dom-anchor.ts
|
|
6
|
+
/**
|
|
7
|
+
* Turns a clicked DOM node into an opaque `CommentAnchor` string, and back.
|
|
8
|
+
*
|
|
9
|
+
* The library's comment system keys everything on an anchor string that content
|
|
10
|
+
* registers via `registerAnchor`. Playground artifacts are arbitrary TSX that
|
|
11
|
+
* register nothing, so the anchor is a CSS selector computed at click time and
|
|
12
|
+
* resolved again on load. Alongside it a comment stores further independent
|
|
13
|
+
* locators (role and name, text under its heading, text in its landmark), so
|
|
14
|
+
* one broken selector does not lose the element. A comment none of them can
|
|
15
|
+
* find yields an *orphan* — kept and flagged, never silently dropped — and one
|
|
16
|
+
* found by a fallback is reported as moved, never silently repositioned.
|
|
17
|
+
* Rendered markdown is the exception: there the anchor is structural — the
|
|
18
|
+
* block's heading path and text (see markdown-anchor.ts) — and is its only locator.
|
|
19
|
+
*/
|
|
20
|
+
var ROOT_ANCHOR = ":scope";
|
|
21
|
+
var MAX_LABEL_TEXT = 60;
|
|
22
|
+
var OVERLAY_SEPARATOR = " >> ";
|
|
23
|
+
var OVERLAY_ANCHOR = /^\[role="dialog"\]\[aria-label="((?:[^"\\]|\\.)*)"\] >> /;
|
|
24
|
+
/** Page authors pin a comment target explicitly with this attribute. */
|
|
25
|
+
var OPT_IN_ATTR = "data-comment-anchor";
|
|
26
|
+
var STABLE_ATTRS = /* @__PURE__ */ new Set([OPT_IN_ATTR, "data-testid"]);
|
|
27
|
+
var SEMANTIC_ATTRS = /* @__PURE__ */ new Set([
|
|
28
|
+
"role",
|
|
29
|
+
"aria-label",
|
|
30
|
+
"name"
|
|
31
|
+
]);
|
|
32
|
+
/** Attributes the playground and React Grab add themselves; they say nothing about the artifact. */
|
|
33
|
+
var TOOLING_ATTR = /^data-(?:react-grab|review|comment|show-rejected)/;
|
|
34
|
+
/**
|
|
35
|
+
* An empty `data-*` attribute marks a component's region (clicky-ui writes
|
|
36
|
+
* e.g. `data-lint-filter-bar=""`), so it names the element wherever it moves.
|
|
37
|
+
* A valued one carries state or row identity and would churn.
|
|
38
|
+
*/
|
|
39
|
+
function isMarkerAttr(name, value) {
|
|
40
|
+
return name.startsWith("data-") && value === "" && !TOOLING_ATTR.test(name);
|
|
41
|
+
}
|
|
42
|
+
var ANONYMOUS_ROLES = /* @__PURE__ */ new Set([
|
|
43
|
+
"generic",
|
|
44
|
+
"presentation",
|
|
45
|
+
"none"
|
|
46
|
+
]);
|
|
47
|
+
var HEADING_SELECTORS = [
|
|
48
|
+
"h1",
|
|
49
|
+
"h2",
|
|
50
|
+
"h3",
|
|
51
|
+
"h4",
|
|
52
|
+
"h5",
|
|
53
|
+
"h6",
|
|
54
|
+
"[role=\"heading\"]",
|
|
55
|
+
"figcaption",
|
|
56
|
+
"legend"
|
|
57
|
+
];
|
|
58
|
+
var HEADING = HEADING_SELECTORS.join(",");
|
|
59
|
+
var CAPTION = "figcaption,legend";
|
|
60
|
+
/** Siblings that are blocks of their own: their heading titles them, not the target. */
|
|
61
|
+
var BLOCK = "section,article,figure,li";
|
|
62
|
+
var GENERATED_IDS = [
|
|
63
|
+
/^(?::r[0-9a-z]+:|«r[0-9a-z]+»|_r_[0-9a-z]+_)/i,
|
|
64
|
+
/^r[0-9a-v]{1,5}(?:-|$)/,
|
|
65
|
+
/^(?:radix|headlessui|react-aria)[-:]/,
|
|
66
|
+
/^mui-\d/
|
|
67
|
+
];
|
|
68
|
+
/**
|
|
69
|
+
* Whether an id was generated at render time and so moves whenever the tree
|
|
70
|
+
* above it changes. A false positive only makes a selector longer.
|
|
71
|
+
*/
|
|
72
|
+
function isGeneratedId(id) {
|
|
73
|
+
return GENERATED_IDS.some((pattern) => pattern.test(id));
|
|
74
|
+
}
|
|
75
|
+
/** Builds a selector locating `target` within `root`, never keyed on a generated id or a styling class. */
|
|
76
|
+
function cssPath(target, root) {
|
|
77
|
+
if (target === root) return ROOT_ANCHOR;
|
|
78
|
+
const optIn = target.getAttribute(OPT_IN_ATTR);
|
|
79
|
+
if (optIn) {
|
|
80
|
+
const selector = `[${OPT_IN_ATTR}="${CSS.escape(optIn)}"]`;
|
|
81
|
+
if (queryAll(root, selector).length === 1) return selector;
|
|
82
|
+
}
|
|
83
|
+
return finder(target, {
|
|
84
|
+
root,
|
|
85
|
+
idName: (id) => !isGeneratedId(id),
|
|
86
|
+
className: () => false,
|
|
87
|
+
attr: (name, value) => STABLE_ATTRS.has(name) || isMarkerAttr(name, value) || SEMANTIC_ATTRS.has(name) && attr(name, value)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function normalizeText(text) {
|
|
91
|
+
return (text ?? "").replace(/\s+/g, " ").trim();
|
|
92
|
+
}
|
|
93
|
+
function fitsText(text) {
|
|
94
|
+
return text !== "" && text.length <= 200;
|
|
95
|
+
}
|
|
96
|
+
function single(elements) {
|
|
97
|
+
return elements.length === 1 ? elements[0] ?? null : null;
|
|
98
|
+
}
|
|
99
|
+
function headingOf(element) {
|
|
100
|
+
const selector = HEADING_SELECTORS.find((candidate) => element.matches(candidate));
|
|
101
|
+
const text = normalizeText(element.textContent);
|
|
102
|
+
return selector && fitsText(text) ? {
|
|
103
|
+
selector,
|
|
104
|
+
text
|
|
105
|
+
} : null;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The heading that titles the block `target` sits in: the nearest preceding
|
|
109
|
+
* sibling heading (or wrapper led by one) at any level up to `root`, or the
|
|
110
|
+
* caption of an enclosing figure or fieldset.
|
|
111
|
+
*/
|
|
112
|
+
function nearestHeading(target, root) {
|
|
113
|
+
for (let node = target; node && node !== root; node = node.parentElement) {
|
|
114
|
+
for (let sibling = node.previousElementSibling; sibling; sibling = sibling.previousElementSibling) {
|
|
115
|
+
const lead = sibling.firstElementChild;
|
|
116
|
+
const heading = sibling.matches(HEADING) ? sibling : !sibling.matches(BLOCK) && lead?.matches(HEADING) ? lead : null;
|
|
117
|
+
const found = heading && headingOf(heading);
|
|
118
|
+
if (found) return found;
|
|
119
|
+
}
|
|
120
|
+
const caption = node.parentElement ? [...node.parentElement.children].find((child) => child !== node && child.matches(CAPTION)) : void 0;
|
|
121
|
+
const found = caption && headingOf(caption);
|
|
122
|
+
if (found) return found;
|
|
123
|
+
}
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
/** Selector of the nearest ancestor with a stable, unique id. */
|
|
127
|
+
function landmarkOf(target, root) {
|
|
128
|
+
for (let node = target.parentElement; node && node !== root; node = node.parentElement) {
|
|
129
|
+
const id = node.getAttribute("id");
|
|
130
|
+
if (!id || isGeneratedId(id)) continue;
|
|
131
|
+
const selector = `#${CSS.escape(id)}`;
|
|
132
|
+
if (queryAll(root, selector).length === 1) return selector;
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
function textMatches(scope, tag, text) {
|
|
137
|
+
return [scope, ...queryAll(scope, tag)].filter((element) => element.tagName.toLowerCase() === tag && normalizeText(element.textContent) === text);
|
|
138
|
+
}
|
|
139
|
+
/** Finds the one element a locator describes, or null when none or several match. */
|
|
140
|
+
function resolveLocator(root, locator) {
|
|
141
|
+
switch (locator.kind) {
|
|
142
|
+
case "css": return query(root, locator.selector);
|
|
143
|
+
case "role": return single(queryAll(root, locator.tag).filter((element) => getRole(element) === locator.role && computeAccessibleName(element) === locator.name));
|
|
144
|
+
case "text": {
|
|
145
|
+
const scope = locator.scope ? query(root, locator.scope) : root;
|
|
146
|
+
if (!scope) return null;
|
|
147
|
+
const { heading } = locator;
|
|
148
|
+
if (!heading) return single(textMatches(scope, locator.tag, locator.text));
|
|
149
|
+
for (let block = single(queryAll(scope, heading.selector).filter((element) => normalizeText(element.textContent) === heading.text)); block && scope.contains(block); block = block.parentElement) {
|
|
150
|
+
const found = textMatches(block, locator.tag, locator.text);
|
|
151
|
+
if (found.length > 0) return single(found);
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
case "markdown": {
|
|
156
|
+
const markdown = markdownRootIn(root);
|
|
157
|
+
return markdown ? resolveMarkdown(markdown, locator)?.element ?? null : null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** The rendered markdown inside (or at) `root`, if the page is a markdown document. */
|
|
162
|
+
function markdownRootIn(root) {
|
|
163
|
+
return root.matches("[data-annotated-markdown]") ? root : root.querySelector(MARKDOWN_ROOT);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Every locator that singles `target` out within `root` right now, strongest
|
|
167
|
+
* first. Candidates that are ambiguous at capture time are dropped, so a stored
|
|
168
|
+
* locator always pointed at exactly this element once.
|
|
169
|
+
*/
|
|
170
|
+
function captureLocators(target, root) {
|
|
171
|
+
if (target === root || !root.contains(target)) return [];
|
|
172
|
+
const markdown = markdownTarget(target);
|
|
173
|
+
if (markdown) return [markdownLocator(markdown.block, markdown.root)];
|
|
174
|
+
const tag = target.tagName.toLowerCase();
|
|
175
|
+
const candidates = [];
|
|
176
|
+
const selector = cssPath(target, root);
|
|
177
|
+
if (selector.length <= 1024) candidates.push({
|
|
178
|
+
kind: "css",
|
|
179
|
+
selector
|
|
180
|
+
});
|
|
181
|
+
const role = getRole(target);
|
|
182
|
+
const name = computeAccessibleName(target);
|
|
183
|
+
if (role && !ANONYMOUS_ROLES.has(role) && fitsText(name)) candidates.push({
|
|
184
|
+
kind: "role",
|
|
185
|
+
tag,
|
|
186
|
+
role,
|
|
187
|
+
name
|
|
188
|
+
});
|
|
189
|
+
const text = normalizeText(target.textContent);
|
|
190
|
+
if (fitsText(text)) {
|
|
191
|
+
const heading = nearestHeading(target, root);
|
|
192
|
+
if (heading) candidates.push({
|
|
193
|
+
kind: "text",
|
|
194
|
+
tag,
|
|
195
|
+
text,
|
|
196
|
+
heading
|
|
197
|
+
});
|
|
198
|
+
const scope = landmarkOf(target, root);
|
|
199
|
+
if (scope) candidates.push({
|
|
200
|
+
kind: "text",
|
|
201
|
+
tag,
|
|
202
|
+
text,
|
|
203
|
+
scope
|
|
204
|
+
});
|
|
205
|
+
candidates.push({
|
|
206
|
+
kind: "text",
|
|
207
|
+
tag,
|
|
208
|
+
text
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
return candidates.filter((locator) => resolveLocator(root, locator) === target);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Locators for a comment stored before locators were captured, read back from
|
|
215
|
+
* the element HTML it kept. Truncated HTML has lost its text, so yields none.
|
|
216
|
+
*/
|
|
217
|
+
function legacyLocators(html) {
|
|
218
|
+
if (html.endsWith("\n<!-- …truncated to 4KB -->")) return [];
|
|
219
|
+
const template = document.createElement("template");
|
|
220
|
+
template.innerHTML = html;
|
|
221
|
+
const element = template.content.firstElementChild;
|
|
222
|
+
const text = normalizeText(element?.textContent ?? null);
|
|
223
|
+
if (!element || !fitsText(text)) return [];
|
|
224
|
+
const tag = element.tagName.toLowerCase();
|
|
225
|
+
const inner = element.querySelector(HEADING);
|
|
226
|
+
const heading = inner && headingOf(inner);
|
|
227
|
+
return [...heading ? [{
|
|
228
|
+
kind: "text",
|
|
229
|
+
tag,
|
|
230
|
+
text,
|
|
231
|
+
heading
|
|
232
|
+
}] : [], {
|
|
233
|
+
kind: "text",
|
|
234
|
+
tag,
|
|
235
|
+
text
|
|
236
|
+
}];
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Resolves a comment through its anchor and every stored locator. The element
|
|
240
|
+
* most of them agree on wins (ties go to the earlier, stronger one), so a
|
|
241
|
+
* stale `nth-child` anchor that now hits a sibling is outvoted rather than
|
|
242
|
+
* trusted.
|
|
243
|
+
*/
|
|
244
|
+
function resolveComment(root, anchor, locators) {
|
|
245
|
+
const matches = [];
|
|
246
|
+
const anchored = resolveAnchor(root, anchor);
|
|
247
|
+
if (anchored) matches.push({
|
|
248
|
+
by: "anchor",
|
|
249
|
+
element: anchored
|
|
250
|
+
});
|
|
251
|
+
return electElement([...matches, ...locatorVotes(root, locators)]);
|
|
252
|
+
}
|
|
253
|
+
function locatorVotes(root, locators) {
|
|
254
|
+
return locators.flatMap((locator) => {
|
|
255
|
+
const element = resolveLocator(root, locator);
|
|
256
|
+
return element ? [{
|
|
257
|
+
by: locator,
|
|
258
|
+
element
|
|
259
|
+
}] : [];
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
/** Prefix of an element anchor: `e:` + JSON of the element's `CommentLocator[]`. */
|
|
263
|
+
var ELEMENT_PREFIX = "e:";
|
|
264
|
+
/** The anchor for an element, given the locators `captureLocators` found for it. */
|
|
265
|
+
function elementAnchor(locators) {
|
|
266
|
+
if (locators.length === 0) throw new Error("an element anchor needs at least one locator");
|
|
267
|
+
return `e:${JSON.stringify(locators)}`;
|
|
268
|
+
}
|
|
269
|
+
function isElementAnchor(anchor) {
|
|
270
|
+
return anchor.startsWith("e:");
|
|
271
|
+
}
|
|
272
|
+
/** The locators an `e:` anchor holds; throws for any other anchor or malformed JSON. */
|
|
273
|
+
function parseElementAnchor(anchor) {
|
|
274
|
+
if (!isElementAnchor(anchor)) throw new Error(`expected an "e:" element anchor, got ${JSON.stringify(anchor.slice(0, 40))}`);
|
|
275
|
+
let parsed;
|
|
276
|
+
try {
|
|
277
|
+
parsed = JSON.parse(anchor.slice(2));
|
|
278
|
+
} catch (cause) {
|
|
279
|
+
throw new Error(`element anchor is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
280
|
+
}
|
|
281
|
+
if (!Array.isArray(parsed) || parsed.length === 0 || parsed.some((item) => typeof item !== "object" || item === null || typeof item.kind !== "string")) throw new Error("element anchor is not a non-empty list of locators");
|
|
282
|
+
return parsed;
|
|
283
|
+
}
|
|
284
|
+
/** Resolves an `e:` anchor's locators within `root`; null when none finds the element (orphaned). */
|
|
285
|
+
function resolveElementAnchor(root, anchor) {
|
|
286
|
+
return electElement(locatorVotes(root, parseElementAnchor(anchor)));
|
|
287
|
+
}
|
|
288
|
+
function electElement(matches) {
|
|
289
|
+
const first = matches[0];
|
|
290
|
+
if (!first) return null;
|
|
291
|
+
const votes = /* @__PURE__ */ new Map();
|
|
292
|
+
for (const { element } of matches) votes.set(element, (votes.get(element) ?? 0) + 1);
|
|
293
|
+
const winner = matches.reduce((best, match) => (votes.get(match.element) ?? 0) > (votes.get(best.element) ?? 0) ? match : best, first);
|
|
294
|
+
return {
|
|
295
|
+
element: winner.element,
|
|
296
|
+
matchedBy: winner.by,
|
|
297
|
+
conflict: votes.size > 1
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* The element a click comments on: inside rendered markdown, the block holding
|
|
302
|
+
* it (or the whole page between blocks); elsewhere the clicked element itself.
|
|
303
|
+
*/
|
|
304
|
+
function commentTarget(target, content) {
|
|
305
|
+
if (!content.contains(target) || !target.closest("[data-annotated-markdown]")) return target;
|
|
306
|
+
return markdownTarget(target)?.block ?? content;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Builds the anchor for a clicked element. Elements inside the artifact get a
|
|
310
|
+
* path from `content`. Overlays (e.g. `Modal`) portal into `document.body`, so
|
|
311
|
+
* an element inside a titled dialog is keyed on that dialog's `aria-label`
|
|
312
|
+
* followed by a path within it. Anything else is not commentable (null).
|
|
313
|
+
*/
|
|
314
|
+
function commentAnchor(target, content) {
|
|
315
|
+
if (content.contains(target)) {
|
|
316
|
+
const element = commentTarget(target, content);
|
|
317
|
+
const markdown = markdownTarget(element);
|
|
318
|
+
return markdown ? markdownAnchor(markdownLocator(markdown.block, markdown.root)) : cssPath(element, content);
|
|
319
|
+
}
|
|
320
|
+
const dialog = target.closest("[role=\"dialog\"][aria-label]");
|
|
321
|
+
const label = dialog?.getAttribute("aria-label");
|
|
322
|
+
if (!dialog || !label) return null;
|
|
323
|
+
return `[role="dialog"][aria-label="${label.replace(/["\\]/g, "\\$&")}"]${OVERLAY_SEPARATOR}${cssPath(target, dialog)}`;
|
|
324
|
+
}
|
|
325
|
+
/** The dialog title an overlay anchor is keyed on, or null for artifact anchors. */
|
|
326
|
+
function overlayLabel(anchor) {
|
|
327
|
+
const match = OVERLAY_ANCHOR.exec(anchor);
|
|
328
|
+
return match?.[1] ? match[1].replace(/\\(["\\])/g, "$1") : null;
|
|
329
|
+
}
|
|
330
|
+
/** Resolves a stored anchor, returning null when the node is gone (orphaned). */
|
|
331
|
+
function resolveAnchor(root, anchor) {
|
|
332
|
+
if (anchor === ROOT_ANCHOR) return root;
|
|
333
|
+
const markdown = parseMarkdownAnchor(anchor);
|
|
334
|
+
if (markdown) {
|
|
335
|
+
const scope = markdownRootIn(root);
|
|
336
|
+
const found = scope && resolveMarkdown(scope, markdown);
|
|
337
|
+
return found?.how === "exact" ? found.element : null;
|
|
338
|
+
}
|
|
339
|
+
const separator = anchor.indexOf(OVERLAY_SEPARATOR);
|
|
340
|
+
if (separator !== -1) {
|
|
341
|
+
const dialog = query(root.ownerDocument, anchor.slice(0, separator));
|
|
342
|
+
const path = anchor.slice(separator + 4);
|
|
343
|
+
return dialog && (path === ROOT_ANCHOR ? dialog : query(dialog, path));
|
|
344
|
+
}
|
|
345
|
+
return [...root.querySelectorAll("[data-comment-anchor]")].find((element) => element.getAttribute("data-comment-anchor") === anchor) ?? query(root, anchor);
|
|
346
|
+
}
|
|
347
|
+
function queryAll(root, selector) {
|
|
348
|
+
try {
|
|
349
|
+
return [...root.querySelectorAll(selector)];
|
|
350
|
+
} catch {
|
|
351
|
+
return [];
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function query(root, selector) {
|
|
355
|
+
return single(queryAll(root, selector));
|
|
356
|
+
}
|
|
357
|
+
/** Short human description of an element, used as the anchor's sidebar label. */
|
|
358
|
+
function describeElement(element) {
|
|
359
|
+
const tag = element.tagName.toLowerCase();
|
|
360
|
+
const classes = (element.getAttribute("class") ?? "").trim().split(/\s+/).filter(Boolean).slice(0, 2);
|
|
361
|
+
const head = classes.length > 0 ? `${tag}.${classes.join(".")}` : tag;
|
|
362
|
+
const text = (element.textContent ?? "").replace(/\s+/g, " ").trim();
|
|
363
|
+
if (text === "") return head;
|
|
364
|
+
return `${head} "${text.length > MAX_LABEL_TEXT ? `${text.slice(0, MAX_LABEL_TEXT)}…` : text}"`;
|
|
365
|
+
}
|
|
366
|
+
/** Re-expresses a viewport rect in the scrollable coordinate space of `root`. */
|
|
367
|
+
function boxWithin(target, root, scroll) {
|
|
368
|
+
return {
|
|
369
|
+
left: target.left - root.left + scroll.left,
|
|
370
|
+
top: target.top - root.top + scroll.top,
|
|
371
|
+
width: target.width,
|
|
372
|
+
height: target.height
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
/** DOM wrapper around `boxWithin` for a live element. */
|
|
376
|
+
function elementBoxWithin(element, root) {
|
|
377
|
+
return boxWithin(element.getBoundingClientRect(), root.getBoundingClientRect(), {
|
|
378
|
+
left: root.scrollLeft,
|
|
379
|
+
top: root.scrollTop
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
export { ELEMENT_PREFIX, boxWithin, captureLocators, commentAnchor, commentTarget, cssPath, describeElement, elementAnchor, elementBoxWithin, isElementAnchor, isGeneratedId, legacyLocators, nearestHeading, overlayLabel, parseElementAnchor, resolveAnchor, resolveComment, resolveElementAnchor, resolveLocator };
|
|
383
|
+
|
|
384
|
+
//# sourceMappingURL=dom-anchor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-anchor.js","names":["wordLikeAttr"],"sources":["../../../src/comments/anchoring/dom-anchor.ts"],"sourcesContent":["/**\n * Turns a clicked DOM node into an opaque `CommentAnchor` string, and back.\n *\n * The library's comment system keys everything on an anchor string that content\n * registers via `registerAnchor`. Playground artifacts are arbitrary TSX that\n * register nothing, so the anchor is a CSS selector computed at click time and\n * resolved again on load. Alongside it a comment stores further independent\n * locators (role and name, text under its heading, text in its landmark), so\n * one broken selector does not lose the element. A comment none of them can\n * find yields an *orphan* — kept and flagged, never silently dropped — and one\n * found by a fallback is reported as moved, never silently repositioned.\n * Rendered markdown is the exception: there the anchor is structural — the\n * block's heading path and text (see markdown-anchor.ts) — and is its only locator.\n */\nimport { attr as wordLikeAttr, finder } from \"@medv/finder\";\nimport { computeAccessibleName, getRole } from \"dom-accessibility-api\";\n\nimport {\n COMMENT_ELEMENT_HTML_TRUNCATION,\n COMMENT_LOCATOR_SELECTOR_LIMIT,\n COMMENT_LOCATOR_TEXT_LIMIT,\n type CommentLocator,\n type CommentLocatorHeading,\n} from \"./model\";\nimport {\n MARKDOWN_ROOT,\n markdownAnchor,\n markdownLocator,\n markdownTarget,\n parseMarkdownAnchor,\n resolveMarkdown,\n} from \"./markdown-anchor\";\n\nexport type Box = { left: number; top: number; width: number; height: number };\n\nconst ROOT_ANCHOR = \":scope\";\nconst MAX_LABEL_TEXT = 60;\nconst OVERLAY_SEPARATOR = \" >> \";\nconst OVERLAY_ANCHOR =\n /^\\[role=\"dialog\"\\]\\[aria-label=\"((?:[^\"\\\\]|\\\\.)*)\"\\] >> /;\n\n/** Page authors pin a comment target explicitly with this attribute. */\nconst OPT_IN_ATTR = \"data-comment-anchor\";\nconst STABLE_ATTRS = new Set([OPT_IN_ATTR, \"data-testid\"]);\nconst SEMANTIC_ATTRS = new Set([\"role\", \"aria-label\", \"name\"]);\n/** Attributes the playground and React Grab add themselves; they say nothing about the artifact. */\nconst TOOLING_ATTR = /^data-(?:react-grab|review|comment|show-rejected)/;\n\n/**\n * An empty `data-*` attribute marks a component's region (clicky-ui writes\n * e.g. `data-lint-filter-bar=\"\"`), so it names the element wherever it moves.\n * A valued one carries state or row identity and would churn.\n */\nfunction isMarkerAttr(name: string, value: string): boolean {\n return name.startsWith(\"data-\") && value === \"\" && !TOOLING_ATTR.test(name);\n}\nconst ANONYMOUS_ROLES = new Set([\"generic\", \"presentation\", \"none\"]);\nconst HEADING_SELECTORS = [\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n '[role=\"heading\"]',\n \"figcaption\",\n \"legend\",\n];\nconst HEADING = HEADING_SELECTORS.join(\",\");\nconst CAPTION = \"figcaption,legend\";\n/** Siblings that are blocks of their own: their heading titles them, not the target. */\nconst BLOCK = \"section,article,figure,li\";\n\nconst GENERATED_IDS = [\n // React useId, raw: :r1n7: (18), «r1» (19.0–19.1), _r_1n7_ (19.2)\n /^(?::r[0-9a-z]+:|«r[0-9a-z]+»|_r_[0-9a-z]+_)/i,\n // React useId with its delimiters stripped, as facet's Diagram does: r1n7-serve\n /^r[0-9a-v]{1,5}(?:-|$)/,\n /^(?:radix|headlessui|react-aria)[-:]/,\n /^mui-\\d/,\n];\n\n/**\n * Whether an id was generated at render time and so moves whenever the tree\n * above it changes. A false positive only makes a selector longer.\n */\nexport function isGeneratedId(id: string): boolean {\n return GENERATED_IDS.some((pattern) => pattern.test(id));\n}\n\n/** Builds a selector locating `target` within `root`, never keyed on a generated id or a styling class. */\nexport function cssPath(target: Element, root: Element): string {\n if (target === root) return ROOT_ANCHOR;\n const optIn = target.getAttribute(OPT_IN_ATTR);\n if (optIn) {\n const selector = `[${OPT_IN_ATTR}=\"${CSS.escape(optIn)}\"]`;\n if (queryAll(root, selector).length === 1) return selector;\n }\n return finder(target, {\n root,\n idName: (id) => !isGeneratedId(id),\n className: () => false,\n attr: (name, value) =>\n STABLE_ATTRS.has(name) ||\n isMarkerAttr(name, value) ||\n (SEMANTIC_ATTRS.has(name) && wordLikeAttr(name, value)),\n });\n}\n\nfunction normalizeText(text: string | null): string {\n return (text ?? \"\").replace(/\\s+/g, \" \").trim();\n}\n\nfunction fitsText(text: string): boolean {\n return text !== \"\" && text.length <= COMMENT_LOCATOR_TEXT_LIMIT;\n}\n\nfunction single(elements: Element[]): Element | null {\n return elements.length === 1 ? (elements[0] ?? null) : null;\n}\n\nfunction headingOf(element: Element): CommentLocatorHeading | null {\n const selector = HEADING_SELECTORS.find((candidate) =>\n element.matches(candidate),\n );\n const text = normalizeText(element.textContent);\n return selector && fitsText(text) ? { selector, text } : null;\n}\n\n/**\n * The heading that titles the block `target` sits in: the nearest preceding\n * sibling heading (or wrapper led by one) at any level up to `root`, or the\n * caption of an enclosing figure or fieldset.\n */\nexport function nearestHeading(\n target: Element,\n root: Element,\n): CommentLocatorHeading | null {\n for (\n let node: Element | null = target;\n node && node !== root;\n node = node.parentElement\n ) {\n for (\n let sibling = node.previousElementSibling;\n sibling;\n sibling = sibling.previousElementSibling\n ) {\n const lead = sibling.firstElementChild;\n const heading = sibling.matches(HEADING)\n ? sibling\n : !sibling.matches(BLOCK) && lead?.matches(HEADING)\n ? lead\n : null;\n const found = heading && headingOf(heading);\n if (found) return found;\n }\n const caption = node.parentElement\n ? [...node.parentElement.children].find(\n (child) => child !== node && child.matches(CAPTION),\n )\n : undefined;\n const found = caption && headingOf(caption);\n if (found) return found;\n }\n return null;\n}\n\n/** Selector of the nearest ancestor with a stable, unique id. */\nfunction landmarkOf(target: Element, root: Element): string | null {\n for (\n let node = target.parentElement;\n node && node !== root;\n node = node.parentElement\n ) {\n const id = node.getAttribute(\"id\");\n if (!id || isGeneratedId(id)) continue;\n const selector = `#${CSS.escape(id)}`;\n if (queryAll(root, selector).length === 1) return selector;\n }\n return null;\n}\n\nfunction textMatches(scope: Element, tag: string, text: string): Element[] {\n return [scope, ...queryAll(scope, tag)].filter(\n (element) =>\n element.tagName.toLowerCase() === tag &&\n normalizeText(element.textContent) === text,\n );\n}\n\n/** Finds the one element a locator describes, or null when none or several match. */\nexport function resolveLocator(\n root: Element,\n locator: CommentLocator,\n): Element | null {\n switch (locator.kind) {\n case \"css\":\n return query(root, locator.selector);\n case \"role\":\n return single(\n queryAll(root, locator.tag).filter(\n (element) =>\n getRole(element) === locator.role &&\n computeAccessibleName(element) === locator.name,\n ),\n );\n case \"text\": {\n const scope = locator.scope ? query(root, locator.scope) : root;\n if (!scope) return null;\n const { heading } = locator;\n if (!heading) return single(textMatches(scope, locator.tag, locator.text));\n // Widen from the heading until the text turns up: the nearest block\n // holding it is the heading's own, so repeated text elsewhere is ignored.\n for (\n let block = single(\n queryAll(scope, heading.selector).filter(\n (element) => normalizeText(element.textContent) === heading.text,\n ),\n );\n block && scope.contains(block);\n block = block.parentElement\n ) {\n const found = textMatches(block, locator.tag, locator.text);\n if (found.length > 0) return single(found);\n }\n return null;\n }\n case \"markdown\": {\n const markdown = markdownRootIn(root);\n return markdown ? (resolveMarkdown(markdown, locator)?.element ?? null) : null;\n }\n }\n}\n\n/** The rendered markdown inside (or at) `root`, if the page is a markdown document. */\nfunction markdownRootIn(root: Element): Element | null {\n return root.matches(MARKDOWN_ROOT) ? root : root.querySelector(MARKDOWN_ROOT);\n}\n\n/**\n * Every locator that singles `target` out within `root` right now, strongest\n * first. Candidates that are ambiguous at capture time are dropped, so a stored\n * locator always pointed at exactly this element once.\n */\nexport function captureLocators(\n target: Element,\n root: Element,\n): CommentLocator[] {\n if (target === root || !root.contains(target)) return [];\n const markdown = markdownTarget(target);\n if (markdown) return [markdownLocator(markdown.block, markdown.root)];\n const tag = target.tagName.toLowerCase();\n const candidates: CommentLocator[] = [];\n\n const selector = cssPath(target, root);\n if (selector.length <= COMMENT_LOCATOR_SELECTOR_LIMIT) {\n candidates.push({ kind: \"css\", selector });\n }\n const role = getRole(target);\n const name = computeAccessibleName(target);\n if (role && !ANONYMOUS_ROLES.has(role) && fitsText(name)) {\n candidates.push({ kind: \"role\", tag, role, name });\n }\n const text = normalizeText(target.textContent);\n if (fitsText(text)) {\n const heading = nearestHeading(target, root);\n if (heading) candidates.push({ kind: \"text\", tag, text, heading });\n const scope = landmarkOf(target, root);\n if (scope) candidates.push({ kind: \"text\", tag, text, scope });\n candidates.push({ kind: \"text\", tag, text });\n }\n return candidates.filter(\n (locator) => resolveLocator(root, locator) === target,\n );\n}\n\n/**\n * Locators for a comment stored before locators were captured, read back from\n * the element HTML it kept. Truncated HTML has lost its text, so yields none.\n */\nexport function legacyLocators(html: string): CommentLocator[] {\n if (html.endsWith(COMMENT_ELEMENT_HTML_TRUNCATION)) return [];\n const template = document.createElement(\"template\");\n template.innerHTML = html;\n const element = template.content.firstElementChild;\n const text = normalizeText(element?.textContent ?? null);\n if (!element || !fitsText(text)) return [];\n const tag = element.tagName.toLowerCase();\n const inner = element.querySelector(HEADING);\n const heading = inner && headingOf(inner);\n return [\n ...(heading ? [{ kind: \"text\" as const, tag, text, heading }] : []),\n { kind: \"text\", tag, text },\n ];\n}\n\nexport type CommentMatch = {\n element: Element;\n /** \"anchor\" when the stored anchor itself won; otherwise the fallback that did. */\n matchedBy: \"anchor\" | CommentLocator;\n /** True when the anchor and locators point at different elements. */\n conflict: boolean;\n};\n\n/**\n * Resolves a comment through its anchor and every stored locator. The element\n * most of them agree on wins (ties go to the earlier, stronger one), so a\n * stale `nth-child` anchor that now hits a sibling is outvoted rather than\n * trusted.\n */\nexport function resolveComment(\n root: Element,\n anchor: string,\n locators: readonly CommentLocator[],\n): CommentMatch | null {\n const matches: ElementVote[] = [];\n const anchored = resolveAnchor(root, anchor);\n if (anchored) matches.push({ by: \"anchor\", element: anchored });\n return electElement([...matches, ...locatorVotes(root, locators)]);\n}\n\ntype ElementVote = { by: CommentMatch[\"matchedBy\"]; element: Element };\n\nfunction locatorVotes(root: Element, locators: readonly CommentLocator[]): ElementVote[] {\n return locators.flatMap((locator) => {\n const element = resolveLocator(root, locator);\n return element ? [{ by: locator, element }] : [];\n });\n}\n\n/** Prefix of an element anchor: `e:` + JSON of the element's `CommentLocator[]`. */\nexport const ELEMENT_PREFIX = \"e:\";\n\n/** The anchor for an element, given the locators `captureLocators` found for it. */\nexport function elementAnchor(locators: readonly CommentLocator[]): string {\n if (locators.length === 0) throw new Error(\"an element anchor needs at least one locator\");\n return `${ELEMENT_PREFIX}${JSON.stringify(locators)}`;\n}\n\nexport function isElementAnchor(anchor: string): boolean {\n return anchor.startsWith(ELEMENT_PREFIX);\n}\n\n/** The locators an `e:` anchor holds; throws for any other anchor or malformed JSON. */\nexport function parseElementAnchor(anchor: string): CommentLocator[] {\n if (!isElementAnchor(anchor)) throw new Error(`expected an \"e:\" element anchor, got ${JSON.stringify(anchor.slice(0, 40))}`);\n let parsed: unknown;\n try {\n parsed = JSON.parse(anchor.slice(ELEMENT_PREFIX.length));\n } catch (cause) {\n throw new Error(`element anchor is not valid JSON: ${cause instanceof Error ? cause.message : String(cause)}`);\n }\n if (!Array.isArray(parsed) || parsed.length === 0 || parsed.some((item) => typeof item !== \"object\" || item === null || typeof (item as { kind?: unknown }).kind !== \"string\"))\n throw new Error(\"element anchor is not a non-empty list of locators\");\n return parsed as CommentLocator[];\n}\n\n/** Resolves an `e:` anchor's locators within `root`; null when none finds the element (orphaned). */\nexport function resolveElementAnchor(root: Element, anchor: string): CommentMatch | null {\n return electElement(locatorVotes(root, parseElementAnchor(anchor)));\n}\n\nfunction electElement(matches: readonly ElementVote[]): CommentMatch | null {\n const first = matches[0];\n if (!first) return null;\n\n const votes = new Map<Element, number>();\n for (const { element } of matches) {\n votes.set(element, (votes.get(element) ?? 0) + 1);\n }\n const winner = matches.reduce((best, match) =>\n (votes.get(match.element) ?? 0) > (votes.get(best.element) ?? 0)\n ? match\n : best,\n first);\n return {\n element: winner.element,\n matchedBy: winner.by,\n conflict: votes.size > 1,\n };\n}\n\n/**\n * The element a click comments on: inside rendered markdown, the block holding\n * it (or the whole page between blocks); elsewhere the clicked element itself.\n */\nexport function commentTarget(target: Element, content: Element): Element {\n if (!content.contains(target) || !target.closest(MARKDOWN_ROOT)) return target;\n return markdownTarget(target)?.block ?? content;\n}\n\n/**\n * Builds the anchor for a clicked element. Elements inside the artifact get a\n * path from `content`. Overlays (e.g. `Modal`) portal into `document.body`, so\n * an element inside a titled dialog is keyed on that dialog's `aria-label`\n * followed by a path within it. Anything else is not commentable (null).\n */\nexport function commentAnchor(\n target: Element,\n content: Element,\n): string | null {\n if (content.contains(target)) {\n const element = commentTarget(target, content);\n const markdown = markdownTarget(element);\n return markdown\n ? markdownAnchor(markdownLocator(markdown.block, markdown.root))\n : cssPath(element, content);\n }\n const dialog = target.closest('[role=\"dialog\"][aria-label]');\n const label = dialog?.getAttribute(\"aria-label\");\n if (!dialog || !label) return null;\n const quoted = label.replace(/[\"\\\\]/g, \"\\\\$&\");\n return `[role=\"dialog\"][aria-label=\"${quoted}\"]${OVERLAY_SEPARATOR}${cssPath(target, dialog)}`;\n}\n\n/** The dialog title an overlay anchor is keyed on, or null for artifact anchors. */\nexport function overlayLabel(anchor: string): string | null {\n const match = OVERLAY_ANCHOR.exec(anchor);\n return match?.[1] ? match[1].replace(/\\\\([\"\\\\])/g, \"$1\") : null;\n}\n\n/** Resolves a stored anchor, returning null when the node is gone (orphaned). */\nexport function resolveAnchor(root: Element, anchor: string): Element | null {\n if (anchor === ROOT_ANCHOR) return root;\n const markdown = parseMarkdownAnchor(anchor);\n if (markdown) {\n // The anchor only names the block as it was; a reworded or relocated\n // block is the locator's to find, and reported as moved.\n const scope = markdownRootIn(root);\n const found = scope && resolveMarkdown(scope, markdown);\n return found?.how === \"exact\" ? found.element : null;\n }\n const separator = anchor.indexOf(OVERLAY_SEPARATOR);\n if (separator !== -1) {\n const dialog = query(root.ownerDocument, anchor.slice(0, separator));\n const path = anchor.slice(separator + OVERLAY_SEPARATOR.length);\n return dialog && (path === ROOT_ANCHOR ? dialog : query(dialog, path));\n }\n const named = [...root.querySelectorAll(\"[data-comment-anchor]\")].find(element => element.getAttribute(\"data-comment-anchor\") === anchor);\n return named ?? query(root, anchor);\n}\n\nfunction queryAll(root: ParentNode, selector: string): Element[] {\n try {\n return [...root.querySelectorAll(selector)];\n } catch {\n // A selector stored against an older DOM can be unparseable. Treating that\n // as an orphan is the visible, domain-meaningful outcome — the sidebar says\n // so — whereas throwing would take the whole comment layer down.\n return [];\n }\n}\n\nfunction query(root: ParentNode, selector: string): Element | null {\n return single(queryAll(root, selector));\n}\n\n/** Short human description of an element, used as the anchor's sidebar label. */\nexport function describeElement(element: Element): string {\n const tag = element.tagName.toLowerCase();\n const classes = (element.getAttribute(\"class\") ?? \"\")\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .slice(0, 2);\n const head = classes.length > 0 ? `${tag}.${classes.join(\".\")}` : tag;\n\n const text = (element.textContent ?? \"\").replace(/\\s+/g, \" \").trim();\n if (text === \"\") return head;\n const clipped =\n text.length > MAX_LABEL_TEXT ? `${text.slice(0, MAX_LABEL_TEXT)}…` : text;\n return `${head} \"${clipped}\"`;\n}\n\n/** Re-expresses a viewport rect in the scrollable coordinate space of `root`. */\nexport function boxWithin(\n target: Box,\n root: Box,\n scroll: { left: number; top: number },\n): Box {\n return {\n left: target.left - root.left + scroll.left,\n top: target.top - root.top + scroll.top,\n width: target.width,\n height: target.height,\n };\n}\n\n/** DOM wrapper around `boxWithin` for a live element. */\nexport function elementBoxWithin(element: Element, root: HTMLElement): Box {\n return boxWithin(\n element.getBoundingClientRect(),\n root.getBoundingClientRect(),\n {\n left: root.scrollLeft,\n top: root.scrollTop,\n },\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmCA,IAAM,cAAc;AACpB,IAAM,iBAAiB;AACvB,IAAM,oBAAoB;AAC1B,IAAM,iBACJ;;AAGF,IAAM,cAAc;AACpB,IAAM,+BAAe,IAAI,IAAI,CAAC,aAAa,aAAa,CAAC;AACzD,IAAM,iCAAiB,IAAI,IAAI;CAAC;CAAQ;CAAc;AAAM,CAAC;;AAE7D,IAAM,eAAe;;;;;;AAOrB,SAAS,aAAa,MAAc,OAAwB;CAC1D,OAAO,KAAK,WAAW,OAAO,KAAK,UAAU,MAAM,CAAC,aAAa,KAAK,IAAI;AAC5E;AACA,IAAM,kCAAkB,IAAI,IAAI;CAAC;CAAW;CAAgB;AAAM,CAAC;AACnE,IAAM,oBAAoB;CACxB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,IAAM,UAAU,kBAAkB,KAAK,GAAG;AAC1C,IAAM,UAAU;;AAEhB,IAAM,QAAQ;AAEd,IAAM,gBAAgB;CAEpB;CAEA;CACA;CACA;AACF;;;;;AAMA,SAAgB,cAAc,IAAqB;CACjD,OAAO,cAAc,MAAM,YAAY,QAAQ,KAAK,EAAE,CAAC;AACzD;;AAGA,SAAgB,QAAQ,QAAiB,MAAuB;CAC9D,IAAI,WAAW,MAAM,OAAO;CAC5B,MAAM,QAAQ,OAAO,aAAa,WAAW;CAC7C,IAAI,OAAO;EACT,MAAM,WAAW,IAAI,YAAY,IAAI,IAAI,OAAO,KAAK,EAAE;EACvD,IAAI,SAAS,MAAM,QAAQ,CAAC,CAAC,WAAW,GAAG,OAAO;CACpD;CACA,OAAO,OAAO,QAAQ;EACpB;EACA,SAAS,OAAO,CAAC,cAAc,EAAE;EACjC,iBAAiB;EACjB,OAAO,MAAM,UACX,aAAa,IAAI,IAAI,KACrB,aAAa,MAAM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Q,CAAC;AACxC;;AAGA,SAAgB,gBAAgB,SAA0B;CACxD,MAAM,MAAM,QAAQ,QAAQ,YAAY;CACxC,MAAM,WAAW,QAAQ,aAAa,OAAO,KAAK,GAAA,CAC/C,KAAK,CAAC,CACN,MAAM,KAAK,CAAC,CACZ,OAAO,OAAO,CAAC,CACf,MAAM,GAAG,CAAC;CACb,MAAM,OAAO,QAAQ,SAAS,IAAI,GAAG,IAAI,GAAG,QAAQ,KAAK,GAAG,MAAM;CAElE,MAAM,QAAQ,QAAQ,eAAe,GAAA,CAAI,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;CACnE,IAAI,SAAS,IAAI,OAAO;CAGxB,OAAO,GAAG,KAAK,IADb,KAAK,SAAS,iBAAiB,GAAG,KAAK,MAAM,GAAG,cAAc,EAAE,KAAK,KAC5C;AAC7B;;AAGA,SAAgB,UACd,QACA,MACA,QACK;CACL,OAAO;EACL,MAAM,OAAO,OAAO,KAAK,OAAO,OAAO;EACvC,KAAK,OAAO,MAAM,KAAK,MAAM,OAAO;EACpC,OAAO,OAAO;EACd,QAAQ,OAAO;CACjB;AACF;;AAGA,SAAgB,iBAAiB,SAAkB,MAAwB;CACzE,OAAO,UACL,QAAQ,sBAAsB,GAC9B,KAAK,sBAAsB,GAC3B;EACE,MAAM,KAAK;EACX,KAAK,KAAK;CACZ,CACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/comments/anchoring/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
require("./model.cjs");
|
|
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
|
+
exports.MARKDOWN_ROOT = MARKDOWN_ROOT;
|
|
180
|
+
exports.MARKDOWN_SIMILARITY_THRESHOLD = MARKDOWN_SIMILARITY_THRESHOLD;
|
|
181
|
+
exports.describeMarkdown = describeMarkdown;
|
|
182
|
+
exports.markdownAnchor = markdownAnchor;
|
|
183
|
+
exports.markdownLocator = markdownLocator;
|
|
184
|
+
exports.markdownTarget = markdownTarget;
|
|
185
|
+
exports.parseMarkdownAnchor = parseMarkdownAnchor;
|
|
186
|
+
exports.resolveMarkdown = resolveMarkdown;
|
|
187
|
+
|
|
188
|
+
//# sourceMappingURL=markdown-anchor.cjs.map
|