@flanksource/clicky-ui 0.3.65 → 0.3.67
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 -2
- package/dist/comments/CommentAuthor.cjs +6 -1
- package/dist/comments/CommentAuthor.cjs.map +1 -1
- package/dist/comments/CommentAuthor.d.ts.map +1 -1
- package/dist/comments/CommentAuthor.js +8 -3
- package/dist/comments/CommentAuthor.js.map +1 -1
- package/dist/comments/CommentComposer.cjs +4 -1
- package/dist/comments/CommentComposer.cjs.map +1 -1
- package/dist/comments/CommentComposer.d.ts.map +1 -1
- package/dist/comments/CommentComposer.js +4 -1
- package/dist/comments/CommentComposer.js.map +1 -1
- package/dist/comments/CommentEditor.cjs +3 -6
- package/dist/comments/CommentEditor.cjs.map +1 -1
- package/dist/comments/CommentEditor.d.ts.map +1 -1
- package/dist/comments/CommentEditor.js +3 -6
- package/dist/comments/CommentEditor.js.map +1 -1
- package/dist/comments/CommentProvider.cjs +3 -1
- package/dist/comments/CommentProvider.cjs.map +1 -1
- package/dist/comments/CommentProvider.d.ts +2 -0
- package/dist/comments/CommentProvider.d.ts.map +1 -1
- package/dist/comments/CommentProvider.js +3 -1
- package/dist/comments/CommentProvider.js.map +1 -1
- package/dist/comments/CommentRail.cjs +31 -18
- package/dist/comments/CommentRail.cjs.map +1 -1
- package/dist/comments/CommentRail.d.ts.map +1 -1
- package/dist/comments/CommentRail.js +31 -18
- package/dist/comments/CommentRail.js.map +1 -1
- package/dist/comments/agent-delivery.cjs +1 -2
- package/dist/comments/agent-delivery.cjs.map +1 -1
- package/dist/comments/agent-delivery.d.ts +1 -1
- package/dist/comments/agent-delivery.d.ts.map +1 -1
- package/dist/comments/agent-delivery.js +1 -2
- package/dist/comments/agent-delivery.js.map +1 -1
- package/dist/comments/annotation-types.d.ts +16 -0
- package/dist/comments/annotation-types.d.ts.map +1 -1
- package/dist/comments/comment-context.cjs.map +1 -1
- package/dist/comments/comment-context.d.ts +2 -1
- package/dist/comments/comment-context.d.ts.map +1 -1
- package/dist/comments/comment-context.js.map +1 -1
- package/dist/comments/comment-types.cjs.map +1 -1
- package/dist/comments/comment-types.d.ts +10 -1
- package/dist/comments/comment-types.d.ts.map +1 -1
- package/dist/comments/comment-types.js.map +1 -1
- package/dist/comments/gavel/CommentAgentSessions.cjs +55 -44
- package/dist/comments/gavel/CommentAgentSessions.cjs.map +1 -1
- package/dist/comments/gavel/CommentAgentSessions.d.ts +5 -2
- package/dist/comments/gavel/CommentAgentSessions.d.ts.map +1 -1
- package/dist/comments/gavel/CommentAgentSessions.js +55 -44
- package/dist/comments/gavel/CommentAgentSessions.js.map +1 -1
- package/dist/comments/gavel/client.cjs +3 -1
- package/dist/comments/gavel/client.cjs.map +1 -1
- package/dist/comments/gavel/client.d.ts.map +1 -1
- package/dist/comments/gavel/client.js +3 -1
- package/dist/comments/gavel/client.js.map +1 -1
- package/dist/comments/gavel/comment-agent-model.cjs +1 -1
- package/dist/comments/gavel/comment-agent-model.cjs.map +1 -1
- package/dist/comments/gavel/comment-agent-model.js +1 -1
- package/dist/comments/gavel/comment-agent-model.js.map +1 -1
- package/dist/comments/gavel/inbox-prompt.cjs +3 -1
- package/dist/comments/gavel/inbox-prompt.cjs.map +1 -1
- package/dist/comments/gavel/inbox-prompt.d.ts.map +1 -1
- package/dist/comments/gavel/inbox-prompt.js +3 -1
- package/dist/comments/gavel/inbox-prompt.js.map +1 -1
- package/dist/comments/gavel/index.d.ts +2 -1
- package/dist/comments/gavel/index.d.ts.map +1 -1
- package/dist/comments/gavel/useGavelComments.cjs +17 -9
- package/dist/comments/gavel/useGavelComments.cjs.map +1 -1
- package/dist/comments/gavel/useGavelComments.d.ts.map +1 -1
- package/dist/comments/gavel/useGavelComments.js +18 -10
- package/dist/comments/gavel/useGavelComments.js.map +1 -1
- package/dist/comments-gavel.cjs +4 -0
- package/dist/comments-gavel.js +3 -1
- package/dist/comments.d.ts +1 -1
- package/dist/comments.d.ts.map +1 -1
- package/dist/components/FilterBar.cjs +12 -5
- package/dist/components/FilterBar.cjs.map +1 -1
- package/dist/components/FilterBar.d.ts.map +1 -1
- package/dist/components/FilterBar.js +12 -5
- package/dist/components/FilterBar.js.map +1 -1
- package/dist/components/JsonSchemaForm.cjs +4 -1
- package/dist/components/JsonSchemaForm.cjs.map +1 -1
- package/dist/components/JsonSchemaForm.d.ts.map +1 -1
- package/dist/components/JsonSchemaForm.js +4 -1
- package/dist/components/JsonSchemaForm.js.map +1 -1
- package/dist/components/SecretFormField.cjs +3 -0
- package/dist/components/SecretFormField.cjs.map +1 -1
- package/dist/components/SecretFormField.d.ts.map +1 -1
- package/dist/components/SecretFormField.js +3 -0
- package/dist/components/SecretFormField.js.map +1 -1
- package/dist/components/SecretKeySelector.cjs +28 -2
- package/dist/components/SecretKeySelector.cjs.map +1 -1
- package/dist/components/SecretKeySelector.d.ts +7 -1
- package/dist/components/SecretKeySelector.d.ts.map +1 -1
- package/dist/components/SecretKeySelector.js +28 -2
- package/dist/components/SecretKeySelector.js.map +1 -1
- package/dist/components/SegmentedControl.cjs +4 -1
- package/dist/components/SegmentedControl.cjs.map +1 -1
- package/dist/components/SegmentedControl.d.ts +3 -3
- package/dist/components/SegmentedControl.d.ts.map +1 -1
- package/dist/components/SegmentedControl.js +5 -2
- package/dist/components/SegmentedControl.js.map +1 -1
- package/dist/components/WorkspaceAccessDialog.cjs +273 -99
- package/dist/components/WorkspaceAccessDialog.cjs.map +1 -1
- package/dist/components/WorkspaceAccessDialog.d.ts +4 -2
- package/dist/components/WorkspaceAccessDialog.d.ts.map +1 -1
- package/dist/components/WorkspaceAccessDialog.js +275 -101
- package/dist/components/WorkspaceAccessDialog.js.map +1 -1
- package/dist/components/json-schema-form-accordion-array.cjs +5 -3
- package/dist/components/json-schema-form-accordion-array.cjs.map +1 -1
- package/dist/components/json-schema-form-accordion-array.d.ts.map +1 -1
- package/dist/components/json-schema-form-accordion-array.js +7 -5
- package/dist/components/json-schema-form-accordion-array.js.map +1 -1
- package/dist/components/json-schema-form-cards-array.cjs +1 -0
- package/dist/components/json-schema-form-cards-array.cjs.map +1 -1
- package/dist/components/json-schema-form-cards-array.d.ts.map +1 -1
- package/dist/components/json-schema-form-cards-array.js +2 -1
- package/dist/components/json-schema-form-cards-array.js.map +1 -1
- package/dist/components/json-schema-form-conditionals.cjs +1 -4
- package/dist/components/json-schema-form-conditionals.cjs.map +1 -1
- package/dist/components/json-schema-form-conditionals.d.ts.map +1 -1
- package/dist/components/json-schema-form-conditionals.js +1 -4
- package/dist/components/json-schema-form-conditionals.js.map +1 -1
- package/dist/components/json-schema-form-enum-choice.cjs +4 -3
- package/dist/components/json-schema-form-enum-choice.cjs.map +1 -1
- package/dist/components/json-schema-form-enum-choice.d.ts.map +1 -1
- package/dist/components/json-schema-form-enum-choice.js +4 -3
- package/dist/components/json-schema-form-enum-choice.js.map +1 -1
- package/dist/components/json-schema-form-item-row.cjs +4 -0
- package/dist/components/json-schema-form-item-row.cjs.map +1 -1
- package/dist/components/json-schema-form-item-row.d.ts +3 -0
- package/dist/components/json-schema-form-item-row.d.ts.map +1 -1
- package/dist/components/json-schema-form-item-row.js +5 -2
- package/dist/components/json-schema-form-item-row.js.map +1 -1
- package/dist/components/json-schema-form-item-summary.cjs +10 -0
- package/dist/components/json-schema-form-item-summary.cjs.map +1 -1
- package/dist/components/json-schema-form-item-summary.d.ts +1 -0
- package/dist/components/json-schema-form-item-summary.d.ts.map +1 -1
- package/dist/components/json-schema-form-item-summary.js +10 -1
- package/dist/components/json-schema-form-item-summary.js.map +1 -1
- package/dist/components/json-schema-form-listeners.cjs +1 -5
- package/dist/components/json-schema-form-listeners.cjs.map +1 -1
- package/dist/components/json-schema-form-listeners.js +1 -5
- package/dist/components/json-schema-form-listeners.js.map +1 -1
- package/dist/components/json-schema-form-refs.cjs +29 -4
- package/dist/components/json-schema-form-refs.cjs.map +1 -1
- package/dist/components/json-schema-form-refs.js +29 -4
- package/dist/components/json-schema-form-refs.js.map +1 -1
- package/dist/components/json-schema-form-render.cjs +35 -13
- package/dist/components/json-schema-form-render.cjs.map +1 -1
- package/dist/components/json-schema-form-render.d.ts.map +1 -1
- package/dist/components/json-schema-form-render.js +36 -14
- package/dist/components/json-schema-form-render.js.map +1 -1
- package/dist/components/json-schema-form-resolve.cjs +3 -1
- package/dist/components/json-schema-form-resolve.cjs.map +1 -1
- package/dist/components/json-schema-form-resolve.d.ts.map +1 -1
- package/dist/components/json-schema-form-resolve.js +3 -1
- package/dist/components/json-schema-form-resolve.js.map +1 -1
- package/dist/components/json-schema-form-runtime-types.d.ts +8 -0
- package/dist/components/json-schema-form-runtime-types.d.ts.map +1 -1
- package/dist/components/json-schema-form-table-array.cjs +1 -1
- package/dist/components/json-schema-form-table-array.cjs.map +1 -1
- package/dist/components/json-schema-form-table-array.js +2 -2
- package/dist/components/json-schema-form-table-array.js.map +1 -1
- package/dist/components/json-schema-form-types.d.ts +6 -0
- package/dist/components/json-schema-form-types.d.ts.map +1 -1
- package/dist/components/json-schema-form-utils.cjs +12 -3
- package/dist/components/json-schema-form-utils.cjs.map +1 -1
- package/dist/components/json-schema-form-utils.d.ts +4 -1
- package/dist/components/json-schema-form-utils.d.ts.map +1 -1
- package/dist/components/json-schema-form-utils.js +12 -3
- package/dist/components/json-schema-form-utils.js.map +1 -1
- package/dist/components/secret-form-extension.cjs.map +1 -1
- package/dist/components/secret-form-extension.d.ts +2 -0
- package/dist/components/secret-form-extension.d.ts.map +1 -1
- package/dist/components/secret-form-extension.js.map +1 -1
- package/dist/components/useSingleRowTagCount.cjs +16 -13
- package/dist/components/useSingleRowTagCount.cjs.map +1 -1
- package/dist/components/useSingleRowTagCount.d.ts +0 -5
- package/dist/components/useSingleRowTagCount.d.ts.map +1 -1
- package/dist/components/useSingleRowTagCount.js +16 -13
- package/dist/components/useSingleRowTagCount.js.map +1 -1
- package/dist/components.cjs +4 -0
- package/dist/components.d.ts +2 -0
- package/dist/components.d.ts.map +1 -1
- package/dist/components.js +3 -1
- package/dist/connections/connectionSchemaFormExtensions.cjs +13 -2
- package/dist/connections/connectionSchemaFormExtensions.cjs.map +1 -1
- package/dist/connections/connectionSchemaFormExtensions.d.ts.map +1 -1
- package/dist/connections/connectionSchemaFormExtensions.js +13 -2
- package/dist/connections/connectionSchemaFormExtensions.js.map +1 -1
- package/dist/data/DataTable.cjs +128 -82
- package/dist/data/DataTable.cjs.map +1 -1
- package/dist/data/DataTable.d.ts +29 -0
- package/dist/data/DataTable.d.ts.map +1 -1
- package/dist/data/DataTable.js +129 -83
- package/dist/data/DataTable.js.map +1 -1
- package/dist/data/DataTableList.cjs +43 -0
- package/dist/data/DataTableList.cjs.map +1 -0
- package/dist/data/DataTableList.d.ts +13 -0
- package/dist/data/DataTableList.d.ts.map +1 -0
- package/dist/data/DataTableList.js +43 -0
- package/dist/data/DataTableList.js.map +1 -0
- package/dist/data/DataTableOverflowCue.cjs +18 -8
- package/dist/data/DataTableOverflowCue.cjs.map +1 -1
- package/dist/data/DataTableOverflowCue.d.ts.map +1 -1
- package/dist/data/DataTableOverflowCue.js +18 -8
- package/dist/data/DataTableOverflowCue.js.map +1 -1
- package/dist/data/Markdown.cjs +11 -1
- package/dist/data/Markdown.cjs.map +1 -1
- package/dist/data/Markdown.d.ts.map +1 -1
- package/dist/data/Markdown.js +11 -1
- package/dist/data/Markdown.js.map +1 -1
- package/dist/data/PromptBanner.cjs +13 -4
- package/dist/data/PromptBanner.cjs.map +1 -1
- package/dist/data/PromptBanner.d.ts.map +1 -1
- package/dist/data/PromptBanner.js +13 -4
- package/dist/data/PromptBanner.js.map +1 -1
- package/dist/data/SelectionActionBar.cjs +20 -5
- package/dist/data/SelectionActionBar.cjs.map +1 -1
- package/dist/data/SelectionActionBar.d.ts +6 -1
- package/dist/data/SelectionActionBar.d.ts.map +1 -1
- package/dist/data/SelectionActionBar.js +20 -5
- package/dist/data/SelectionActionBar.js.map +1 -1
- package/dist/data/StatStrip.cjs +12 -4
- package/dist/data/StatStrip.cjs.map +1 -1
- package/dist/data/StatStrip.d.ts +0 -8
- package/dist/data/StatStrip.d.ts.map +1 -1
- package/dist/data/StatStrip.js +12 -4
- package/dist/data/StatStrip.js.map +1 -1
- package/dist/data/TaskManager.cjs +173 -53
- package/dist/data/TaskManager.cjs.map +1 -1
- package/dist/data/TaskManager.d.ts +9 -1
- package/dist/data/TaskManager.d.ts.map +1 -1
- package/dist/data/TaskManager.js +175 -55
- package/dist/data/TaskManager.js.map +1 -1
- package/dist/data/TaskPoolUsage.cjs +65 -1
- package/dist/data/TaskPoolUsage.cjs.map +1 -1
- package/dist/data/TaskPoolUsage.d.ts +19 -1
- package/dist/data/TaskPoolUsage.d.ts.map +1 -1
- package/dist/data/TaskPoolUsage.js +65 -2
- package/dist/data/TaskPoolUsage.js.map +1 -1
- package/dist/data/ai/SessionInspector.cjs +24 -14
- package/dist/data/ai/SessionInspector.cjs.map +1 -1
- package/dist/data/ai/SessionInspector.collection.cjs +9 -7
- package/dist/data/ai/SessionInspector.collection.cjs.map +1 -1
- package/dist/data/ai/SessionInspector.collection.d.ts +1 -1
- package/dist/data/ai/SessionInspector.collection.d.ts.map +1 -1
- package/dist/data/ai/SessionInspector.collection.js +9 -7
- package/dist/data/ai/SessionInspector.collection.js.map +1 -1
- package/dist/data/ai/SessionInspector.d.ts +8 -3
- package/dist/data/ai/SessionInspector.d.ts.map +1 -1
- package/dist/data/ai/SessionInspector.hierarchy-state.cjs +5 -4
- package/dist/data/ai/SessionInspector.hierarchy-state.cjs.map +1 -1
- package/dist/data/ai/SessionInspector.hierarchy-state.js +6 -5
- package/dist/data/ai/SessionInspector.hierarchy-state.js.map +1 -1
- package/dist/data/ai/SessionInspector.host-tabs.cjs +28 -0
- package/dist/data/ai/SessionInspector.host-tabs.cjs.map +1 -0
- package/dist/data/ai/SessionInspector.host-tabs.d.ts +17 -0
- package/dist/data/ai/SessionInspector.host-tabs.d.ts.map +1 -0
- package/dist/data/ai/SessionInspector.host-tabs.js +28 -0
- package/dist/data/ai/SessionInspector.host-tabs.js.map +1 -0
- package/dist/data/ai/SessionInspector.js +24 -14
- package/dist/data/ai/SessionInspector.js.map +1 -1
- package/dist/data/ai/SessionInspector.legacy.cjs +13 -6
- package/dist/data/ai/SessionInspector.legacy.cjs.map +1 -1
- package/dist/data/ai/SessionInspector.legacy.d.ts +3 -1
- package/dist/data/ai/SessionInspector.legacy.d.ts.map +1 -1
- package/dist/data/ai/SessionInspector.legacy.js +13 -6
- package/dist/data/ai/SessionInspector.legacy.js.map +1 -1
- package/dist/data/ai/SessionInspector.remote.cjs +7 -3
- package/dist/data/ai/SessionInspector.remote.cjs.map +1 -1
- package/dist/data/ai/SessionInspector.remote.d.ts +1 -1
- package/dist/data/ai/SessionInspector.remote.d.ts.map +1 -1
- package/dist/data/ai/SessionInspector.remote.js +8 -4
- package/dist/data/ai/SessionInspector.remote.js.map +1 -1
- package/dist/data/ai/SessionViewer.input.cjs +78 -1
- package/dist/data/ai/SessionViewer.input.cjs.map +1 -1
- package/dist/data/ai/SessionViewer.input.d.ts +9 -0
- package/dist/data/ai/SessionViewer.input.d.ts.map +1 -1
- package/dist/data/ai/SessionViewer.input.js +77 -2
- package/dist/data/ai/SessionViewer.input.js.map +1 -1
- package/dist/data/ai/SessionViewer.tool-details.cjs +44 -13
- package/dist/data/ai/SessionViewer.tool-details.cjs.map +1 -1
- package/dist/data/ai/SessionViewer.tool-details.d.ts +7 -1
- package/dist/data/ai/SessionViewer.tool-details.d.ts.map +1 -1
- package/dist/data/ai/SessionViewer.tool-details.js +44 -13
- package/dist/data/ai/SessionViewer.tool-details.js.map +1 -1
- package/dist/data/ai/SessionViewer.tool-row.cjs +7 -3
- package/dist/data/ai/SessionViewer.tool-row.cjs.map +1 -1
- package/dist/data/ai/SessionViewer.tool-row.d.ts.map +1 -1
- package/dist/data/ai/SessionViewer.tool-row.js +8 -4
- package/dist/data/ai/SessionViewer.tool-row.js.map +1 -1
- package/dist/data/ai/index.d.ts +1 -1
- package/dist/data/ai/index.d.ts.map +1 -1
- package/dist/data/ai/runtime-preset-menu/use-runtime-preset-menu.cjs +5 -2
- package/dist/data/ai/runtime-preset-menu/use-runtime-preset-menu.cjs.map +1 -1
- package/dist/data/ai/runtime-preset-menu/use-runtime-preset-menu.d.ts.map +1 -1
- package/dist/data/ai/runtime-preset-menu/use-runtime-preset-menu.js +6 -3
- package/dist/data/ai/runtime-preset-menu/use-runtime-preset-menu.js.map +1 -1
- package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.cjs +2 -1
- package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.cjs.map +1 -1
- package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.d.ts.map +1 -1
- package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.js +2 -1
- package/dist/data/ai/runtime-profiles/RuntimeProfilesWorkspace.js.map +1 -1
- package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.cjs +2 -1
- package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.cjs.map +1 -1
- package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.d.ts.map +1 -1
- package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.js +2 -1
- package/dist/data/ai/runtime-profiles/use-runtime-profile-picker.js.map +1 -1
- package/dist/data/ai/use-session-scroll.cjs +120 -41
- package/dist/data/ai/use-session-scroll.cjs.map +1 -1
- package/dist/data/ai/use-session-scroll.d.ts +3 -3
- package/dist/data/ai/use-session-scroll.d.ts.map +1 -1
- package/dist/data/ai/use-session-scroll.js +120 -41
- package/dist/data/ai/use-session-scroll.js.map +1 -1
- package/dist/data/cells/timestamp-format.cjs +57 -2
- package/dist/data/cells/timestamp-format.cjs.map +1 -1
- package/dist/data/cells/timestamp-format.d.ts +9 -1
- package/dist/data/cells/timestamp-format.d.ts.map +1 -1
- package/dist/data/cells/timestamp-format.js +56 -3
- package/dist/data/cells/timestamp-format.js.map +1 -1
- package/dist/data/chat/AgentIdentity.cjs +10 -3
- package/dist/data/chat/AgentIdentity.cjs.map +1 -1
- package/dist/data/chat/AgentIdentity.d.ts +2 -1
- package/dist/data/chat/AgentIdentity.d.ts.map +1 -1
- package/dist/data/chat/AgentIdentity.js +10 -3
- package/dist/data/chat/AgentIdentity.js.map +1 -1
- package/dist/data/chat/Conversation.cjs +14 -5
- package/dist/data/chat/Conversation.cjs.map +1 -1
- package/dist/data/chat/Conversation.d.ts.map +1 -1
- package/dist/data/chat/Conversation.js +14 -5
- package/dist/data/chat/Conversation.js.map +1 -1
- package/dist/data/data-table-list.cjs +24 -0
- package/dist/data/data-table-list.cjs.map +1 -0
- package/dist/data/data-table-list.d.ts +31 -0
- package/dist/data/data-table-list.d.ts.map +1 -0
- package/dist/data/data-table-list.js +24 -0
- package/dist/data/data-table-list.js.map +1 -0
- package/dist/data/delimited.cjs +48 -0
- package/dist/data/delimited.cjs.map +1 -0
- package/dist/data/delimited.d.ts +10 -0
- package/dist/data/delimited.d.ts.map +1 -0
- package/dist/data/delimited.js +47 -0
- package/dist/data/delimited.js.map +1 -0
- package/dist/data/git/index.d.ts +1 -0
- package/dist/data/git/index.d.ts.map +1 -1
- package/dist/data/git/pickers/GitPickers.cjs +2 -0
- package/dist/data/git/pickers/GitPickers.cjs.map +1 -1
- package/dist/data/git/pickers/GitPickers.d.ts.map +1 -1
- package/dist/data/git/pickers/GitPickers.js +2 -0
- package/dist/data/git/pickers/GitPickers.js.map +1 -1
- package/dist/data/git/pickers/GitSourcePicker.cjs +9 -2
- package/dist/data/git/pickers/GitSourcePicker.cjs.map +1 -1
- package/dist/data/git/pickers/GitSourcePicker.d.ts.map +1 -1
- package/dist/data/git/pickers/GitSourcePicker.js +9 -2
- package/dist/data/git/pickers/GitSourcePicker.js.map +1 -1
- package/dist/data/git/pickers/ReferencePicker.cjs +60 -6
- package/dist/data/git/pickers/ReferencePicker.cjs.map +1 -1
- package/dist/data/git/pickers/ReferencePicker.d.ts +9 -1
- package/dist/data/git/pickers/ReferencePicker.d.ts.map +1 -1
- package/dist/data/git/pickers/ReferencePicker.js +61 -7
- package/dist/data/git/pickers/ReferencePicker.js.map +1 -1
- package/dist/data/git/pickers/git-ref-group-limits.cjs +14 -0
- package/dist/data/git/pickers/git-ref-group-limits.cjs.map +1 -0
- package/dist/data/git/pickers/git-ref-group-limits.d.ts +11 -0
- package/dist/data/git/pickers/git-ref-group-limits.d.ts.map +1 -0
- package/dist/data/git/pickers/git-ref-group-limits.js +14 -0
- package/dist/data/git/pickers/git-ref-group-limits.js.map +1 -0
- package/dist/data/git/pickers/types.d.ts +2 -0
- package/dist/data/git/pickers/types.d.ts.map +1 -1
- package/dist/data/lint/LintList.cjs +154 -0
- package/dist/data/lint/LintList.cjs.map +1 -0
- package/dist/data/lint/LintList.d.ts +14 -0
- package/dist/data/lint/LintList.d.ts.map +1 -0
- package/dist/data/lint/LintList.js +154 -0
- package/dist/data/lint/LintList.js.map +1 -0
- package/dist/data/lint/LintResults.cjs +31 -10
- package/dist/data/lint/LintResults.cjs.map +1 -1
- package/dist/data/lint/LintResults.d.ts +5 -3
- package/dist/data/lint/LintResults.d.ts.map +1 -1
- package/dist/data/lint/LintResults.js +31 -10
- package/dist/data/lint/LintResults.js.map +1 -1
- package/dist/data/lint/actions.cjs +3 -1
- package/dist/data/lint/actions.cjs.map +1 -1
- package/dist/data/lint/actions.d.ts.map +1 -1
- package/dist/data/lint/actions.js +3 -1
- package/dist/data/lint/actions.js.map +1 -1
- package/dist/data/lint/index.d.ts +2 -0
- package/dist/data/lint/index.d.ts.map +1 -1
- package/dist/data/lint/list-grouping.cjs +39 -0
- package/dist/data/lint/list-grouping.cjs.map +1 -0
- package/dist/data/lint/list-grouping.d.ts +20 -0
- package/dist/data/lint/list-grouping.d.ts.map +1 -0
- package/dist/data/lint/list-grouping.js +39 -0
- package/dist/data/lint/list-grouping.js.map +1 -0
- package/dist/data/task-run-format.cjs +20 -0
- package/dist/data/task-run-format.cjs.map +1 -0
- package/dist/data/task-run-format.d.ts +6 -0
- package/dist/data/task-run-format.d.ts.map +1 -0
- package/dist/data/task-run-format.js +20 -0
- package/dist/data/task-run-format.js.map +1 -0
- package/dist/data/test-runner/TestDetailPanel.cjs +15 -4
- package/dist/data/test-runner/TestDetailPanel.cjs.map +1 -1
- package/dist/data/test-runner/TestDetailPanel.d.ts.map +1 -1
- package/dist/data/test-runner/TestDetailPanel.js +16 -5
- package/dist/data/test-runner/TestDetailPanel.js.map +1 -1
- package/dist/data/test-runner/TestList.cjs +87 -0
- package/dist/data/test-runner/TestList.cjs.map +1 -0
- package/dist/data/test-runner/TestList.d.ts +9 -0
- package/dist/data/test-runner/TestList.d.ts.map +1 -0
- package/dist/data/test-runner/TestList.js +87 -0
- package/dist/data/test-runner/TestList.js.map +1 -0
- package/dist/data/test-runner/TestRunner.cjs +21 -2
- package/dist/data/test-runner/TestRunner.cjs.map +1 -1
- package/dist/data/test-runner/TestRunner.d.ts +9 -1
- package/dist/data/test-runner/TestRunner.d.ts.map +1 -1
- package/dist/data/test-runner/TestRunner.js +21 -2
- package/dist/data/test-runner/TestRunner.js.map +1 -1
- package/dist/data/test-runner/TestTreeNode.cjs +1 -1
- package/dist/data/test-runner/TestTreeNode.cjs.map +1 -1
- package/dist/data/test-runner/TestTreeNode.js +1 -1
- package/dist/data/test-runner/TestTreeNode.js.map +1 -1
- package/dist/data/test-runner/TestViewToggle.cjs +32 -0
- package/dist/data/test-runner/TestViewToggle.cjs.map +1 -0
- package/dist/data/test-runner/TestViewToggle.d.ts +5 -0
- package/dist/data/test-runner/TestViewToggle.d.ts.map +1 -0
- package/dist/data/test-runner/TestViewToggle.js +32 -0
- package/dist/data/test-runner/TestViewToggle.js.map +1 -0
- package/dist/data/test-runner/adapter.cjs +14 -0
- package/dist/data/test-runner/adapter.cjs.map +1 -1
- package/dist/data/test-runner/adapter.d.ts +15 -0
- package/dist/data/test-runner/adapter.d.ts.map +1 -1
- package/dist/data/test-runner/adapter.js +14 -0
- package/dist/data/test-runner/adapter.js.map +1 -1
- package/dist/data/test-runner/context.cjs.map +1 -1
- package/dist/data/test-runner/context.d.ts +5 -0
- package/dist/data/test-runner/context.d.ts.map +1 -1
- package/dist/data/test-runner/context.js.map +1 -1
- package/dist/data/test-runner/index.d.ts +3 -0
- package/dist/data/test-runner/index.d.ts.map +1 -1
- package/dist/data/test-runner/status.cjs +5 -0
- package/dist/data/test-runner/status.cjs.map +1 -1
- package/dist/data/test-runner/status.d.ts +2 -0
- package/dist/data/test-runner/status.d.ts.map +1 -1
- package/dist/data/test-runner/status.js +5 -1
- package/dist/data/test-runner/status.js.map +1 -1
- package/dist/data/traces/index.d.ts +2 -1
- package/dist/data/traces/index.d.ts.map +1 -1
- package/dist/data/traces/otel/OtelTraceBrowser.cjs +173 -0
- package/dist/data/traces/otel/OtelTraceBrowser.cjs.map +1 -0
- package/dist/data/traces/otel/OtelTraceBrowser.d.ts +31 -0
- package/dist/data/traces/otel/OtelTraceBrowser.d.ts.map +1 -0
- package/dist/data/traces/otel/OtelTraceBrowser.js +173 -0
- package/dist/data/traces/otel/OtelTraceBrowser.js.map +1 -0
- package/dist/data/traces/otel/OtelTraceDetail.cjs +6 -4
- package/dist/data/traces/otel/OtelTraceDetail.cjs.map +1 -1
- package/dist/data/traces/otel/OtelTraceDetail.d.ts +5 -1
- package/dist/data/traces/otel/OtelTraceDetail.d.ts.map +1 -1
- package/dist/data/traces/otel/OtelTraceDetail.js +6 -4
- package/dist/data/traces/otel/OtelTraceDetail.js.map +1 -1
- package/dist/data/traces/otel/OtelTraceSearch.cjs +2 -1
- package/dist/data/traces/otel/OtelTraceSearch.cjs.map +1 -1
- package/dist/data/traces/otel/OtelTraceSearch.d.ts +3 -1
- package/dist/data/traces/otel/OtelTraceSearch.d.ts.map +1 -1
- package/dist/data/traces/otel/OtelTraceSearch.js +2 -1
- package/dist/data/traces/otel/OtelTraceSearch.js.map +1 -1
- package/dist/data/traces/otel/OtelTraceTable.cjs +62 -6
- package/dist/data/traces/otel/OtelTraceTable.cjs.map +1 -1
- package/dist/data/traces/otel/OtelTraceTable.d.ts +22 -1
- package/dist/data/traces/otel/OtelTraceTable.d.ts.map +1 -1
- package/dist/data/traces/otel/OtelTraceTable.js +62 -6
- package/dist/data/traces/otel/OtelTraceTable.js.map +1 -1
- package/dist/data/traces/otel/QueryBar.cjs +23 -10
- package/dist/data/traces/otel/QueryBar.cjs.map +1 -1
- package/dist/data/traces/otel/QueryBar.d.ts +3 -1
- package/dist/data/traces/otel/QueryBar.d.ts.map +1 -1
- package/dist/data/traces/otel/QueryBar.js +23 -10
- package/dist/data/traces/otel/QueryBar.js.map +1 -1
- package/dist/data/traces/otel/browser-state.cjs +86 -0
- package/dist/data/traces/otel/browser-state.cjs.map +1 -0
- package/dist/data/traces/otel/browser-state.d.ts +22 -0
- package/dist/data/traces/otel/browser-state.d.ts.map +1 -0
- package/dist/data/traces/otel/browser-state.js +83 -0
- package/dist/data/traces/otel/browser-state.js.map +1 -0
- package/dist/data/version-info.cjs +3 -3
- package/dist/data/version-info.js +3 -3
- package/dist/data.cjs +17 -0
- package/dist/data.d.ts +3 -3
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +10 -3
- package/dist/file-findings/file-review/FileReview.cjs +38 -11
- package/dist/file-findings/file-review/FileReview.cjs.map +1 -1
- package/dist/file-findings/file-review/FileReview.d.ts.map +1 -1
- package/dist/file-findings/file-review/FileReview.js +39 -12
- package/dist/file-findings/file-review/FileReview.js.map +1 -1
- package/dist/file-findings/file-review/geometry.cjs +20 -15
- package/dist/file-findings/file-review/geometry.cjs.map +1 -1
- package/dist/file-findings/file-review/geometry.d.ts +5 -3
- package/dist/file-findings/file-review/geometry.d.ts.map +1 -1
- package/dist/file-findings/file-review/geometry.js +21 -16
- package/dist/file-findings/file-review/geometry.js.map +1 -1
- package/dist/file-findings/file-review/patch-comments.cjs +23 -16
- package/dist/file-findings/file-review/patch-comments.cjs.map +1 -1
- package/dist/file-findings/file-review/patch-comments.d.ts +22 -12
- package/dist/file-findings/file-review/patch-comments.d.ts.map +1 -1
- package/dist/file-findings/file-review/patch-comments.js +23 -17
- package/dist/file-findings/file-review/patch-comments.js.map +1 -1
- package/dist/file-findings/file-review/quote-anchor.cjs +23 -9
- package/dist/file-findings/file-review/quote-anchor.cjs.map +1 -1
- package/dist/file-findings/file-review/quote-anchor.d.ts +12 -2
- package/dist/file-findings/file-review/quote-anchor.d.ts.map +1 -1
- package/dist/file-findings/file-review/quote-anchor.js +22 -9
- package/dist/file-findings/file-review/quote-anchor.js.map +1 -1
- package/dist/file-findings/file-review/selection-lines.cjs +17 -8
- package/dist/file-findings/file-review/selection-lines.cjs.map +1 -1
- package/dist/file-findings/file-review/selection-lines.d.ts +3 -2
- package/dist/file-findings/file-review/selection-lines.d.ts.map +1 -1
- package/dist/file-findings/file-review/selection-lines.js +17 -8
- package/dist/file-findings/file-review/selection-lines.js.map +1 -1
- package/dist/file-findings/file-review/table-cell.cjs +95 -0
- package/dist/file-findings/file-review/table-cell.cjs.map +1 -0
- package/dist/file-findings/file-review/table-cell.d.ts +31 -0
- package/dist/file-findings/file-review/table-cell.d.ts.map +1 -0
- package/dist/file-findings/file-review/table-cell.js +92 -0
- package/dist/file-findings/file-review/table-cell.js.map +1 -0
- package/dist/file-findings.cjs +2 -0
- package/dist/file-findings.d.ts +1 -0
- package/dist/file-findings.d.ts.map +1 -1
- package/dist/file-findings.js +2 -1
- package/dist/icons/components/UiFolderGit.cjs +8 -8
- package/dist/icons/components/UiFolderGit.cjs.map +1 -1
- package/dist/icons/components/UiFolderGit.js +8 -8
- package/dist/icons/components/UiFolderGit.js.map +1 -1
- package/dist/icons/components/UiUserSwitch.cjs +51 -0
- package/dist/icons/components/UiUserSwitch.cjs.map +1 -0
- package/dist/icons/components/UiUserSwitch.d.ts +15 -0
- package/dist/icons/components/UiUserSwitch.d.ts.map +1 -0
- package/dist/icons/components/UiUserSwitch.js +48 -0
- package/dist/icons/components/UiUserSwitch.js.map +1 -0
- package/dist/icons/index.d.ts +2 -0
- package/dist/icons/index.d.ts.map +1 -1
- package/dist/icons/registry.cjs +2 -0
- package/dist/icons/registry.cjs.map +1 -1
- package/dist/icons/registry.d.ts.map +1 -1
- package/dist/icons/registry.js +2 -0
- package/dist/icons/registry.js.map +1 -1
- package/dist/icons.cjs +3 -0
- package/dist/icons.js +2 -1
- package/dist/index.cjs +23 -0
- package/dist/index.js +13 -3
- package/dist/jvm/model/threads.cjs +1 -1
- package/dist/jvm/model/threads.cjs.map +1 -1
- package/dist/jvm/model/threads.js +1 -1
- package/dist/jvm/model/threads.js.map +1 -1
- package/dist/lib/random-uuid.cjs +12 -0
- package/dist/lib/random-uuid.cjs.map +1 -0
- package/dist/lib/random-uuid.d.ts +2 -0
- package/dist/lib/random-uuid.d.ts.map +1 -0
- package/dist/lib/random-uuid.js +12 -0
- package/dist/lib/random-uuid.js.map +1 -0
- package/dist/overlay/Modal.cjs +22 -11
- package/dist/overlay/Modal.cjs.map +1 -1
- package/dist/overlay/Modal.d.ts +5 -1
- package/dist/overlay/Modal.d.ts.map +1 -1
- package/dist/overlay/Modal.js +22 -11
- package/dist/overlay/Modal.js.map +1 -1
- package/dist/overlay/ModalProvider.cjs +238 -0
- package/dist/overlay/ModalProvider.cjs.map +1 -0
- package/dist/overlay/ModalProvider.d.ts +10 -0
- package/dist/overlay/ModalProvider.d.ts.map +1 -0
- package/dist/overlay/ModalProvider.js +238 -0
- package/dist/overlay/ModalProvider.js.map +1 -0
- package/dist/overlay/modal-context.cjs +12 -0
- package/dist/overlay/modal-context.cjs.map +1 -0
- package/dist/overlay/modal-context.d.ts +46 -0
- package/dist/overlay/modal-context.d.ts.map +1 -0
- package/dist/overlay/modal-context.js +11 -0
- package/dist/overlay/modal-context.js.map +1 -0
- package/dist/overlay/modal-draft-storage.cjs +51 -0
- package/dist/overlay/modal-draft-storage.cjs.map +1 -0
- package/dist/overlay/modal-draft-storage.d.ts +19 -0
- package/dist/overlay/modal-draft-storage.d.ts.map +1 -0
- package/dist/overlay/modal-draft-storage.js +47 -0
- package/dist/overlay/modal-draft-storage.js.map +1 -0
- package/dist/runtime/barrels.json +8696 -8652
- package/dist/runtime/importmap.json +2116 -2103
- package/dist/styles.css +1 -1
- package/dist/utils.cjs +2 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -1
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_table_cell = require("./table-cell.cjs");
|
|
1
2
|
// src/file-findings/file-review/quote-anchor.ts
|
|
2
3
|
var QUOTE_PREFIX = "q:";
|
|
3
4
|
var SOURCE_BLOCK = "[data-source-start]";
|
|
@@ -166,17 +167,29 @@ var QUOTE_TIERS = [...TIERS, {
|
|
|
166
167
|
suffix: false
|
|
167
168
|
}];
|
|
168
169
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
170
|
+
* The rendered elements covering source lines `start`..`end`: each top-level
|
|
171
|
+
* block that overlaps them, or for a table only its rows on those lines.
|
|
172
|
+
*/
|
|
173
|
+
function elementsInLines(root, lines) {
|
|
174
|
+
return sections(root).flatMap(({ block }) => {
|
|
175
|
+
const { sourceStart, sourceEnd } = block.dataset;
|
|
176
|
+
if (Number(sourceStart) > lines.end || Number(sourceEnd) < lines.start) return [];
|
|
177
|
+
const rows = require_table_cell.tableRows(block);
|
|
178
|
+
return rows.length > 0 ? rows.filter(({ line }) => line >= lines.start && line <= lines.end).map(({ row }) => row) : [block];
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Finds a patch's quote again, searching only `within` (the rendered elements
|
|
183
|
+
* where the patch matches now, or the cell it was made in). The words with
|
|
171
184
|
* their context first, then with the context edited away; null once they are
|
|
172
185
|
* gone, or repeat so that nothing tells the occurrences apart, so the caller
|
|
173
186
|
* falls back to highlighting the lines.
|
|
174
187
|
*/
|
|
175
|
-
function
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
188
|
+
function resolveQuoteWithin(within, quote) {
|
|
189
|
+
const candidates = within.map((block) => ({
|
|
190
|
+
block,
|
|
191
|
+
path: []
|
|
192
|
+
}));
|
|
180
193
|
const locator = {
|
|
181
194
|
path: [],
|
|
182
195
|
prefix: quote.prefix,
|
|
@@ -184,7 +197,7 @@ function resolveQuoteInLines(root, lines, quote) {
|
|
|
184
197
|
suffix: quote.suffix
|
|
185
198
|
};
|
|
186
199
|
for (const tier of QUOTE_TIERS) {
|
|
187
|
-
const found = matches(
|
|
200
|
+
const found = matches(candidates, locator, tier);
|
|
188
201
|
if (found.length === 1) return rangeIn(found[0].block, found[0].start, found[0].end);
|
|
189
202
|
if (found.length > 1) return null;
|
|
190
203
|
}
|
|
@@ -272,6 +285,7 @@ function describeQuote(locator) {
|
|
|
272
285
|
exports.QUOTE_PREFIX = QUOTE_PREFIX;
|
|
273
286
|
exports.captureTextQuote = captureTextQuote;
|
|
274
287
|
exports.describeQuote = describeQuote;
|
|
288
|
+
exports.elementsInLines = elementsInLines;
|
|
275
289
|
exports.locateSelection = locateSelection;
|
|
276
290
|
exports.locateSourceSelection = locateSourceSelection;
|
|
277
291
|
exports.markdownOutline = markdownOutline;
|
|
@@ -279,7 +293,7 @@ exports.parseQuoteAnchor = parseQuoteAnchor;
|
|
|
279
293
|
exports.quoteAnchor = quoteAnchor;
|
|
280
294
|
exports.quoteLiesInLines = quoteLiesInLines;
|
|
281
295
|
exports.resolveQuote = resolveQuote;
|
|
282
|
-
exports.
|
|
296
|
+
exports.resolveQuoteWithin = resolveQuoteWithin;
|
|
283
297
|
exports.sourceSpans = sourceSpans;
|
|
284
298
|
|
|
285
299
|
//# sourceMappingURL=quote-anchor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote-anchor.cjs","names":[],"sources":["../../../src/file-findings/file-review/quote-anchor.ts"],"sourcesContent":["// Anchors on words inside rendered markdown, in the spirit of the W3C\n// TextQuoteSelector: a quote is found again through the heading outline (the\n// section it sits in) plus a few words on each side, so the same words\n// elsewhere — or edits to other sections — never move it.\nimport type { TextQuote } from \"../../comments/annotation-types\";\n\n/** A quote inside the section named by `path` (its heading trail), with the words around it. */\nexport type QuoteLocator = { path: string[]; prefix: string; quote: string; suffix: string };\n\nexport const QUOTE_PREFIX = \"q:\";\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\nconst HEADING = /^h([1-6])$/;\n/** Heading text kept in a path; longer headings are cut so stored anchors stay bounded. */\nexport const OUTLINE_HEADING_LIMIT = 200;\n/** Context words taken on each side to start with; grown until the anchor is unique. */\nconst MIN_CONTEXT_WORDS = 2;\n\nexport function quoteAnchor(locator: QuoteLocator): string {\n return `${QUOTE_PREFIX}${JSON.stringify([locator.path, locator.prefix, locator.quote, locator.suffix])}`;\n}\n\n/** The locator a `q:` anchor encodes; throws for a malformed one. */\nexport function parseQuoteAnchor(anchor: string): QuoteLocator {\n if (!anchor.startsWith(QUOTE_PREFIX)) throw new Error(`not a quote anchor: ${JSON.stringify(anchor)}`);\n const parsed: unknown = JSON.parse(anchor.slice(QUOTE_PREFIX.length));\n const [path, prefix, quote, suffix] = Array.isArray(parsed) ? parsed : [];\n if (\n !Array.isArray(path) ||\n !path.every((heading) => typeof heading === \"string\") ||\n typeof prefix !== \"string\" ||\n typeof quote !== \"string\" ||\n typeof suffix !== \"string\"\n ) {\n throw new Error(`malformed quote anchor ${JSON.stringify(anchor)}`);\n }\n return { path, prefix, quote, suffix };\n}\n\n/** A top-level rendered block, the heading trail it sits under, and its first source line. */\nexport type OutlineEntry = { block: Element; path: string[]; line: number };\n\n/**\n * Every top-level block of rendered markdown (`Markdown sourceBlocks`) in\n * document order, with the headings above it: its table-of-contents path.\n */\nexport function markdownOutline(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 const text = blockText(block).replace(/\\s+/g, \" \").trim().slice(0, OUTLINE_HEADING_LIMIT);\n stack.push({ level: Number(level), text });\n }\n return { block, path: stack.map((heading) => heading.text), line: Number((block as HTMLElement).dataset.sourceStart) };\n });\n}\n\ntype Section = Pick<OutlineEntry, \"block\" | \"path\">;\n\nconst sections = (root: Element): Section[] => markdownOutline(root);\n\nfunction textNodes(block: Element): Text[] {\n const walker = document.createTreeWalker(block, NodeFilter.SHOW_TEXT);\n const nodes: Text[] = [];\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (!node.parentElement?.closest(\"[data-comment-author]\")) nodes.push(node as Text);\n }\n return nodes;\n}\n\n/** A block's text exactly as its text nodes concatenate, so offsets map back onto them. */\nfunction blockText(block: Element): string {\n return textNodes(block)\n .map((node) => node.data)\n .join(\"\");\n}\n\nfunction rangeIn(block: Element, start: number, end: number): Range {\n const range = document.createRange();\n let offset = 0;\n let started = false;\n for (const node of textNodes(block)) {\n if (!started && start < offset + node.length) {\n range.setStart(node, start - offset);\n started = true;\n }\n if (started && end <= offset + node.length) {\n range.setEnd(node, end - offset);\n return range;\n }\n offset += node.length;\n }\n throw new Error(`quote-anchor: offsets ${start}-${end} lie outside the block`);\n}\n\n// Rendered cells and list items concatenate without whitespace (\"lead5 min\"),\n// so any run of whitespace in the locator matches zero or more in the text.\nfunction pattern(text: string): string {\n return text\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((word) => word.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n .join(\"\\\\s*\");\n}\n\ntype Match = { block: Element; start: number; end: number };\n\nfunction matches(candidates: readonly Section[], locator: QuoteLocator, context: { prefix: boolean; suffix: boolean }): Match[] {\n const before = context.prefix && locator.prefix.trim() ? `(?<=${pattern(locator.prefix)}\\\\s*)` : \"\";\n const after = context.suffix && locator.suffix.trim() ? `(?=\\\\s*${pattern(locator.suffix)})` : \"\";\n const regex = new RegExp(`${before}${pattern(locator.quote)}${after}`, \"g\");\n return candidates.flatMap(({ block }) =>\n [...blockText(block).matchAll(regex)].map((m) => ({ block, start: m.index, end: m.index + m[0].length })),\n );\n}\n\nconst samePath = (a: readonly string[], b: readonly string[]) => a.length === b.length && a.every((h, i) => h === b[i]);\n\n// Strictest first. A looser tier is tried only when a stricter one finds\n// nothing, so edited context still resolves, but never guesses between two.\nconst TIERS = [\n { prefix: true, suffix: true },\n { prefix: true, suffix: false },\n { prefix: false, suffix: true },\n] as const;\n\n/**\n * Finds a quote again: in its section by quote plus context, then with one\n * side of the context edited away; failing that (a renamed heading), anywhere\n * by the full context. Null when it is gone or ambiguous.\n */\nexport function resolveQuote(root: Element, locator: QuoteLocator): Range | null {\n const all = sections(root);\n const section = all.filter((s) => samePath(s.path, locator.path));\n for (const tier of TIERS) {\n const found = matches(section, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n }\n const relocated = matches(all, locator, TIERS[0]);\n return relocated.length === 1 ? rangeIn(relocated[0]!.block, relocated[0]!.start, relocated[0]!.end) : null;\n}\n\n/**\n * The locator for a selection inside one block, with just enough context on\n * each side to make it unique in its section. Null when the selection spans\n * blocks, is blank, or repeats so exactly that no context tells it apart.\n */\nexport function locateSelection(root: Element, range: Range): QuoteLocator | null {\n const all = sections(root);\n const own = all.find(({ block }) => block.contains(range.startContainer) && block.contains(range.endContainer));\n if (!own) return null;\n const text = blockText(own.block);\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const raw = rangeText(range);\n const start = rangeText(lead).length + (raw.length - raw.trimStart().length);\n const end = rangeText(lead).length + raw.trimEnd().length;\n if (end <= start) return null;\n\n const before = text.slice(0, start).split(/\\s+/).filter(Boolean);\n const after = text.slice(end).split(/\\s+/).filter(Boolean);\n const section = all.filter((s) => samePath(s.path, own.path));\n for (let words = MIN_CONTEXT_WORDS; ; words++) {\n const locator = {\n path: own.path,\n prefix: before.slice(-words).join(\" \"),\n quote: text.slice(start, end),\n suffix: after.slice(0, words).join(\" \"),\n };\n const found = matches(section, locator, TIERS[0]);\n if (found.length === 1 && found[0]!.block === own.block && found[0]!.start === start) return locator;\n if (words >= before.length && words >= after.length) return null;\n }\n}\n\n/** A selection inside one rendered block as the words with the words around them; null when it spans blocks or is blank. */\nexport function captureTextQuote(root: Element, range: Range): TextQuote | null {\n const locator = locateSelection(root, range);\n return locator && { prefix: locator.prefix, exact: locator.quote, suffix: locator.suffix };\n}\n\n/** Context from the strictest tier to none at all: inside a patch's few lines the words alone may be enough. */\nconst QUOTE_TIERS = [...TIERS, { prefix: false, suffix: false }] as const;\n\n/**\n * Finds a patch's quote again, searching only the rendered blocks that cover\n * source lines `start`..`end` (where the patch matches now). The words with\n * their context first, then with the context edited away; null once they are\n * gone, or repeat so that nothing tells the occurrences apart, so the caller\n * falls back to highlighting the lines.\n */\nexport function resolveQuoteInLines(root: Element, lines: { start: number; end: number }, quote: TextQuote): Range | null {\n const covering = sections(root).filter(({ block }) => {\n const { sourceStart, sourceEnd } = (block as HTMLElement).dataset;\n return Number(sourceStart) <= lines.end && Number(sourceEnd) >= lines.start;\n });\n const locator = { path: [], prefix: quote.prefix, quote: quote.exact, suffix: quote.suffix };\n for (const tier of QUOTE_TIERS) {\n const found = matches(covering, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n if (found.length > 1) return null;\n }\n return null;\n}\n\n/**\n * Whether the quote's exact text appears verbatim in the markdown source `lines`:\n * the rule the server enforces on a selector's quote. Rendered text that\n * differs from its source (`**bold**`, links, escapes) therefore does not lie\n * in the lines, and the patch alone anchors the thread.\n */\nexport function quoteLiesInLines(quote: TextQuote, lines: readonly string[]): boolean {\n return quote.exact !== \"\" && lines.join(\"\\n\").includes(quote.exact);\n}\n\n/** A run of characters on one source line (1-based line, 0-based columns). */\nexport type SourceSpan = { line: number; start: number; end: number };\n\n// Markdown markup that renders as nothing (emphasis, code ticks, table pipes,\n// quote and heading markers, list bullets), so it may sit between source words.\nconst MARKUP = /[*_`|>#~]|(?:^|\\s)[-+](?=\\s)/g;\n\nfunction sourcePattern(quote: string): string {\n return pattern(quote.replace(MARKUP, \" \")).replaceAll(\"\\\\s*\", \"[\\\\s*_`|>#~]*\");\n}\n\nfunction sourceBlocks(root: Element, lines: readonly string[]) {\n return sections(root).map(({ block }) => {\n const first = Number((block as HTMLElement).dataset.sourceStart);\n const last = Number((block as HTMLElement).dataset.sourceEnd);\n return { block, first, last, text: lines.slice(first - 1, last).join(\"\\n\") };\n });\n}\n\nconst allMatches = (text: string, source: string) => [...text.matchAll(new RegExp(source, \"g\"))];\n\n/**\n * The quote locator for a selection in the raw markdown: the selection's words\n * are found in the rendered block built from that line, as the same occurrence\n * they are in the source, so a comment made in Source shows in Preview too.\n * Null when the selection is only markup or its block renders no such words.\n */\nexport function locateSourceSelection(root: Element, lines: readonly string[], span: SourceSpan): QuoteLocator | null {\n const selected = lines[span.line - 1]?.slice(span.start, span.end) ?? \"\";\n if (!selected.replace(MARKUP, \" \").trim()) return null;\n const own = sourceBlocks(root, lines).find((b) => span.line >= b.first && span.line <= b.last);\n if (!own) return null;\n const at = lines.slice(own.first - 1, span.line - 1).reduce((sum, l) => sum + l.length + 1, 0) + span.start;\n const k = allMatches(own.text, sourcePattern(selected)).findIndex((m) => m.index + m[0].length > at && m.index < at + selected.length);\n const hit = k < 0 ? undefined : allMatches(blockText(own.block), pattern(selected.replace(MARKUP, \" \")))[k];\n return hit ? locateSelection(root, rangeIn(own.block, hit.index, hit.index + hit[0].length)) : null;\n}\n\n/** Where a quote anchor's text sits in the raw markdown, one span per source line it covers. */\nexport function sourceSpans(root: Element, lines: readonly string[], locator: QuoteLocator): SourceSpan[] {\n const range = resolveQuote(root, locator);\n const own = range && sourceBlocks(root, lines).find(({ block }) => block.contains(range.startContainer));\n if (!range || !own) return [];\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const offset = rangeText(lead).length;\n const k = allMatches(blockText(own.block), pattern(locator.quote)).findIndex((m) => m.index === offset);\n const hit = k < 0 ? undefined : allMatches(own.text, sourcePattern(locator.quote))[k];\n if (!hit) return [];\n const spans: SourceSpan[] = [];\n let lineStart = 0;\n for (let line = own.first; line <= own.last; line++) {\n const text = lines[line - 1] ?? \"\";\n const start = Math.max(hit.index, lineStart) - lineStart;\n const end = Math.min(hit.index + hit[0].length, lineStart + text.length) - lineStart;\n if (end > start) spans.push({ line, start, end });\n lineStart += text.length + 1;\n }\n return spans;\n}\n\nfunction rangeText(range: Range): string {\n const content = range.cloneContents();\n for (const avatar of content.querySelectorAll(\"[data-comment-author]\")) avatar.remove();\n return content.textContent ?? \"\";\n}\n\n/** Reader-facing label: the section and the quoted words. */\nexport function describeQuote(locator: QuoteLocator): string {\n const section = locator.path.at(-1);\n return `${section ? `${section} › ` : \"\"}“${locator.quote}”`;\n}\n"],"mappings":";AASA,IAAa,eAAe;AAE5B,IAAM,eAAe;AACrB,IAAM,UAAU;;AAIhB,IAAM,oBAAoB;AAE1B,SAAgB,YAAY,SAA+B;CACzD,OAAO,KAAkB,KAAK,UAAU;EAAC,QAAQ;EAAM,QAAQ;EAAQ,QAAQ;EAAO,QAAQ;CAAM,CAAC;AACvG;;AAGA,SAAgB,iBAAiB,QAA8B;CAC7D,IAAI,CAAC,OAAO,WAAA,IAAuB,GAAG,MAAM,IAAI,MAAM,uBAAuB,KAAK,UAAU,MAAM,GAAG;CACrG,MAAM,SAAkB,KAAK,MAAM,OAAO,MAAM,CAAmB,CAAC;CACpE,MAAM,CAAC,MAAM,QAAQ,OAAO,UAAU,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC;CACxE,IACE,CAAC,MAAM,QAAQ,IAAI,KACnB,CAAC,KAAK,OAAO,YAAY,OAAO,YAAY,QAAQ,KACpD,OAAO,WAAW,YAClB,OAAO,UAAU,YACjB,OAAO,WAAW,UAElB,MAAM,IAA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AAO,CAAC;CAClB,MAAM,QAAsB,CAAC;CAC7B,IAAI,YAAY;CAChB,KAAK,IAAI,OAAO,IAAI,OAAO,QAAQ,IAAI,MAAM,QAAQ;EACnD,MAAM,OAAO,MAAM,OAAO,MAAM;EAChC,MAAM,QAAQ,KAAK,IAAI,IAAI,OAAO,SAAS,IAAI;EAC/C,MAAM,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,EAAE,CAAC,QAAQ,YAAY,KAAK,MAAM,IAAI;EAC3E,IAAI,MAAM,OAAO,MAAM,KAAK;GAAE;GAAM;GAAO;EAAI,CAAC;EAChD,aAAa,KAAK,SAAS;CAC7B;CACA,OAAO;AACT;AAEA,SAAS,UAAU,OAAsB;CACvC,MAAM,UAAU,MAAM,cAAc;CACpC,KAAK,MAAM,UAAU,QAAQ,iBAAiB,uBAAuB,GAAG,OAAO,OAAO;CACtF,OAAO,QAAQ,eAAe;AAChC;;AAGA,SAAgB,cAAc,SAA+B;CAC3D,MAAM,UAAU,QAAQ,KAAK,GAAG,EAAE;CAClC,OAAO,GAAG,UAAU,GAAG,QAAQ,OAAO,GAAG,GAAG,QAAQ,MAAM;AAC5D"}
|
|
1
|
+
{"version":3,"file":"quote-anchor.cjs","names":["tableRows"],"sources":["../../../src/file-findings/file-review/quote-anchor.ts"],"sourcesContent":["// Anchors on words inside rendered markdown, in the spirit of the W3C\n// TextQuoteSelector: a quote is found again through the heading outline (the\n// section it sits in) plus a few words on each side, so the same words\n// elsewhere — or edits to other sections — never move it.\nimport type { TextQuote } from \"../../comments/annotation-types\";\nimport { tableRows } from \"./table-cell\";\n\n/** A quote inside the section named by `path` (its heading trail), with the words around it. */\nexport type QuoteLocator = { path: string[]; prefix: string; quote: string; suffix: string };\n\nexport const QUOTE_PREFIX = \"q:\";\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\nconst HEADING = /^h([1-6])$/;\n/** Heading text kept in a path; longer headings are cut so stored anchors stay bounded. */\nexport const OUTLINE_HEADING_LIMIT = 200;\n/** Context words taken on each side to start with; grown until the anchor is unique. */\nconst MIN_CONTEXT_WORDS = 2;\n\nexport function quoteAnchor(locator: QuoteLocator): string {\n return `${QUOTE_PREFIX}${JSON.stringify([locator.path, locator.prefix, locator.quote, locator.suffix])}`;\n}\n\n/** The locator a `q:` anchor encodes; throws for a malformed one. */\nexport function parseQuoteAnchor(anchor: string): QuoteLocator {\n if (!anchor.startsWith(QUOTE_PREFIX)) throw new Error(`not a quote anchor: ${JSON.stringify(anchor)}`);\n const parsed: unknown = JSON.parse(anchor.slice(QUOTE_PREFIX.length));\n const [path, prefix, quote, suffix] = Array.isArray(parsed) ? parsed : [];\n if (\n !Array.isArray(path) ||\n !path.every((heading) => typeof heading === \"string\") ||\n typeof prefix !== \"string\" ||\n typeof quote !== \"string\" ||\n typeof suffix !== \"string\"\n ) {\n throw new Error(`malformed quote anchor ${JSON.stringify(anchor)}`);\n }\n return { path, prefix, quote, suffix };\n}\n\n/** A top-level rendered block, the heading trail it sits under, and its first source line. */\nexport type OutlineEntry = { block: Element; path: string[]; line: number };\n\n/**\n * Every top-level block of rendered markdown (`Markdown sourceBlocks`) in\n * document order, with the headings above it: its table-of-contents path.\n */\nexport function markdownOutline(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 const text = blockText(block).replace(/\\s+/g, \" \").trim().slice(0, OUTLINE_HEADING_LIMIT);\n stack.push({ level: Number(level), text });\n }\n return { block, path: stack.map((heading) => heading.text), line: Number((block as HTMLElement).dataset.sourceStart) };\n });\n}\n\ntype Section = Pick<OutlineEntry, \"block\" | \"path\">;\n\nconst sections = (root: Element): Section[] => markdownOutline(root);\n\nfunction textNodes(block: Element): Text[] {\n const walker = document.createTreeWalker(block, NodeFilter.SHOW_TEXT);\n const nodes: Text[] = [];\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (!node.parentElement?.closest(\"[data-comment-author]\")) nodes.push(node as Text);\n }\n return nodes;\n}\n\n/** A block's text exactly as its text nodes concatenate, so offsets map back onto them. */\nfunction blockText(block: Element): string {\n return textNodes(block)\n .map((node) => node.data)\n .join(\"\");\n}\n\nfunction rangeIn(block: Element, start: number, end: number): Range {\n const range = document.createRange();\n let offset = 0;\n let started = false;\n for (const node of textNodes(block)) {\n if (!started && start < offset + node.length) {\n range.setStart(node, start - offset);\n started = true;\n }\n if (started && end <= offset + node.length) {\n range.setEnd(node, end - offset);\n return range;\n }\n offset += node.length;\n }\n throw new Error(`quote-anchor: offsets ${start}-${end} lie outside the block`);\n}\n\n// Rendered cells and list items concatenate without whitespace (\"lead5 min\"),\n// so any run of whitespace in the locator matches zero or more in the text.\nfunction pattern(text: string): string {\n return text\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((word) => word.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n .join(\"\\\\s*\");\n}\n\ntype Match = { block: Element; start: number; end: number };\n\nfunction matches(candidates: readonly Section[], locator: QuoteLocator, context: { prefix: boolean; suffix: boolean }): Match[] {\n const before = context.prefix && locator.prefix.trim() ? `(?<=${pattern(locator.prefix)}\\\\s*)` : \"\";\n const after = context.suffix && locator.suffix.trim() ? `(?=\\\\s*${pattern(locator.suffix)})` : \"\";\n const regex = new RegExp(`${before}${pattern(locator.quote)}${after}`, \"g\");\n return candidates.flatMap(({ block }) =>\n [...blockText(block).matchAll(regex)].map((m) => ({ block, start: m.index, end: m.index + m[0].length })),\n );\n}\n\nconst samePath = (a: readonly string[], b: readonly string[]) => a.length === b.length && a.every((h, i) => h === b[i]);\n\n// Strictest first. A looser tier is tried only when a stricter one finds\n// nothing, so edited context still resolves, but never guesses between two.\nconst TIERS = [\n { prefix: true, suffix: true },\n { prefix: true, suffix: false },\n { prefix: false, suffix: true },\n] as const;\n\n/**\n * Finds a quote again: in its section by quote plus context, then with one\n * side of the context edited away; failing that (a renamed heading), anywhere\n * by the full context. Null when it is gone or ambiguous.\n */\nexport function resolveQuote(root: Element, locator: QuoteLocator): Range | null {\n const all = sections(root);\n const section = all.filter((s) => samePath(s.path, locator.path));\n for (const tier of TIERS) {\n const found = matches(section, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n }\n const relocated = matches(all, locator, TIERS[0]);\n return relocated.length === 1 ? rangeIn(relocated[0]!.block, relocated[0]!.start, relocated[0]!.end) : null;\n}\n\n/**\n * The locator for a selection inside one block, with just enough context on\n * each side to make it unique in its section. Null when the selection spans\n * blocks, is blank, or repeats so exactly that no context tells it apart.\n */\nexport function locateSelection(root: Element, range: Range): QuoteLocator | null {\n const all = sections(root);\n const own = all.find(({ block }) => block.contains(range.startContainer) && block.contains(range.endContainer));\n if (!own) return null;\n const text = blockText(own.block);\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const raw = rangeText(range);\n const start = rangeText(lead).length + (raw.length - raw.trimStart().length);\n const end = rangeText(lead).length + raw.trimEnd().length;\n if (end <= start) return null;\n\n const before = text.slice(0, start).split(/\\s+/).filter(Boolean);\n const after = text.slice(end).split(/\\s+/).filter(Boolean);\n const section = all.filter((s) => samePath(s.path, own.path));\n for (let words = MIN_CONTEXT_WORDS; ; words++) {\n const locator = {\n path: own.path,\n prefix: before.slice(-words).join(\" \"),\n quote: text.slice(start, end),\n suffix: after.slice(0, words).join(\" \"),\n };\n const found = matches(section, locator, TIERS[0]);\n if (found.length === 1 && found[0]!.block === own.block && found[0]!.start === start) return locator;\n if (words >= before.length && words >= after.length) return null;\n }\n}\n\n/** A selection inside one rendered block as the words with the words around them; null when it spans blocks or is blank. */\nexport function captureTextQuote(root: Element, range: Range): TextQuote | null {\n const locator = locateSelection(root, range);\n return locator && { prefix: locator.prefix, exact: locator.quote, suffix: locator.suffix };\n}\n\n/** Context from the strictest tier to none at all: inside a patch's few lines the words alone may be enough. */\nconst QUOTE_TIERS = [...TIERS, { prefix: false, suffix: false }] as const;\n\n/**\n * The rendered elements covering source lines `start`..`end`: each top-level\n * block that overlaps them, or for a table only its rows on those lines.\n */\nexport function elementsInLines(root: Element, lines: { start: number; end: number }): Element[] {\n return sections(root).flatMap(({ block }) => {\n const { sourceStart, sourceEnd } = (block as HTMLElement).dataset;\n if (Number(sourceStart) > lines.end || Number(sourceEnd) < lines.start) return [];\n const rows = tableRows(block);\n return rows.length > 0 ? rows.filter(({ line }) => line >= lines.start && line <= lines.end).map(({ row }) => row) : [block];\n });\n}\n\n/**\n * Finds a patch's quote again, searching only `within` (the rendered elements\n * where the patch matches now, or the cell it was made in). The words with\n * their context first, then with the context edited away; null once they are\n * gone, or repeat so that nothing tells the occurrences apart, so the caller\n * falls back to highlighting the lines.\n */\nexport function resolveQuoteWithin(within: readonly Element[], quote: TextQuote): Range | null {\n const candidates = within.map((block) => ({ block, path: [] }));\n const locator = { path: [], prefix: quote.prefix, quote: quote.exact, suffix: quote.suffix };\n for (const tier of QUOTE_TIERS) {\n const found = matches(candidates, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n if (found.length > 1) return null;\n }\n return null;\n}\n\n/** `resolveQuoteWithin` the elements covering source lines `start`..`end`. */\nexport function resolveQuoteInLines(root: Element, lines: { start: number; end: number }, quote: TextQuote): Range | null {\n return resolveQuoteWithin(elementsInLines(root, lines), quote);\n}\n\n/**\n * Whether the quote's exact text appears verbatim in the markdown source `lines`:\n * the rule the server enforces on a selector's quote. Rendered text that\n * differs from its source (`**bold**`, links, escapes) therefore does not lie\n * in the lines, and the patch alone anchors the thread.\n */\nexport function quoteLiesInLines(quote: TextQuote, lines: readonly string[]): boolean {\n return quote.exact !== \"\" && lines.join(\"\\n\").includes(quote.exact);\n}\n\n/** A run of characters on one source line (1-based line, 0-based columns). */\nexport type SourceSpan = { line: number; start: number; end: number };\n\n// Markdown markup that renders as nothing (emphasis, code ticks, table pipes,\n// quote and heading markers, list bullets), so it may sit between source words.\nconst MARKUP = /[*_`|>#~]|(?:^|\\s)[-+](?=\\s)/g;\n\nfunction sourcePattern(quote: string): string {\n return pattern(quote.replace(MARKUP, \" \")).replaceAll(\"\\\\s*\", \"[\\\\s*_`|>#~]*\");\n}\n\nfunction sourceBlocks(root: Element, lines: readonly string[]) {\n return sections(root).map(({ block }) => {\n const first = Number((block as HTMLElement).dataset.sourceStart);\n const last = Number((block as HTMLElement).dataset.sourceEnd);\n return { block, first, last, text: lines.slice(first - 1, last).join(\"\\n\") };\n });\n}\n\nconst allMatches = (text: string, source: string) => [...text.matchAll(new RegExp(source, \"g\"))];\n\n/**\n * The quote locator for a selection in the raw markdown: the selection's words\n * are found in the rendered block built from that line, as the same occurrence\n * they are in the source, so a comment made in Source shows in Preview too.\n * Null when the selection is only markup or its block renders no such words.\n */\nexport function locateSourceSelection(root: Element, lines: readonly string[], span: SourceSpan): QuoteLocator | null {\n const selected = lines[span.line - 1]?.slice(span.start, span.end) ?? \"\";\n if (!selected.replace(MARKUP, \" \").trim()) return null;\n const own = sourceBlocks(root, lines).find((b) => span.line >= b.first && span.line <= b.last);\n if (!own) return null;\n const at = lines.slice(own.first - 1, span.line - 1).reduce((sum, l) => sum + l.length + 1, 0) + span.start;\n const k = allMatches(own.text, sourcePattern(selected)).findIndex((m) => m.index + m[0].length > at && m.index < at + selected.length);\n const hit = k < 0 ? undefined : allMatches(blockText(own.block), pattern(selected.replace(MARKUP, \" \")))[k];\n return hit ? locateSelection(root, rangeIn(own.block, hit.index, hit.index + hit[0].length)) : null;\n}\n\n/** Where a quote anchor's text sits in the raw markdown, one span per source line it covers. */\nexport function sourceSpans(root: Element, lines: readonly string[], locator: QuoteLocator): SourceSpan[] {\n const range = resolveQuote(root, locator);\n const own = range && sourceBlocks(root, lines).find(({ block }) => block.contains(range.startContainer));\n if (!range || !own) return [];\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const offset = rangeText(lead).length;\n const k = allMatches(blockText(own.block), pattern(locator.quote)).findIndex((m) => m.index === offset);\n const hit = k < 0 ? undefined : allMatches(own.text, sourcePattern(locator.quote))[k];\n if (!hit) return [];\n const spans: SourceSpan[] = [];\n let lineStart = 0;\n for (let line = own.first; line <= own.last; line++) {\n const text = lines[line - 1] ?? \"\";\n const start = Math.max(hit.index, lineStart) - lineStart;\n const end = Math.min(hit.index + hit[0].length, lineStart + text.length) - lineStart;\n if (end > start) spans.push({ line, start, end });\n lineStart += text.length + 1;\n }\n return spans;\n}\n\nfunction rangeText(range: Range): string {\n const content = range.cloneContents();\n for (const avatar of content.querySelectorAll(\"[data-comment-author]\")) avatar.remove();\n return content.textContent ?? \"\";\n}\n\n/** Reader-facing label: the section and the quoted words. */\nexport function describeQuote(locator: QuoteLocator): string {\n const section = locator.path.at(-1);\n return `${section ? `${section} › ` : \"\"}“${locator.quote}”`;\n}\n"],"mappings":";;AAUA,IAAa,eAAe;AAE5B,IAAM,eAAe;AACrB,IAAM,UAAU;;AAIhB,IAAM,oBAAoB;AAE1B,SAAgB,YAAY,SAA+B;CACzD,OAAO,KAAkB,KAAK,UAAU;EAAC,QAAQ;EAAM,QAAQ;EAAQ,QAAQ;EAAO,QAAQ;CAAM,CAAC;AACvG;;AAGA,SAAgB,iBAAiB,QAA8B;CAC7D,IAAI,CAAC,OAAO,WAAA,IAAuB,GAAG,MAAM,IAAI,MAAM,uBAAuB,KAAK,UAAU,MAAM,GAAG;CACrG,MAAM,SAAkB,KAAK,MAAM,OAAO,MAAM,CAAmB,CAAC;CACpE,MAAM,CAAC,MAAM,QAAQ,OAAO,UAAU,MAAM,QAAQ,MAAM,IAAI,SAAS,CAAC;CACxE,IACE,CAAC,MAAM,QAAQ,IAAI,KACnB,CAAC,KAAK,OAAO,YAAY,OAAO,YAAY,QAAQ,KACpD,OA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,SAAS,YAAY;CAClC,KAAK,SAAS,IAAI,OAAO,CAAC;CAC1B,KAAK,OAAO,MAAM,gBAAgB,MAAM,WAAW;CACnD,MAAM,SAAS,UAAU,IAAI,CAAC,CAAC;CAC/B,MAAM,IAAI,WAAW,UAAU,IAAI,KAAK,GAAG,QAAQ,QAAQ,KAAK,CAAC,CAAC,CAAC,WAAW,MAAM,EAAE,UAAU,MAAM;CACtG,MAAM,MAAM,IAAI,IAAI,KAAA,IAAY,WAAW,IAAI,MAAM,cAAc,QAAQ,KAAK,CAAC,CAAC,CAAC;CACnF,IAAI,CAAC,KAAK,OAAO,CAAC;CAClB,MAAM,QAAsB,CAAC;CAC7B,IAAI,YAAY;CAChB,KAAK,IAAI,OAAO,IAAI,OAAO,QAAQ,IAAI,MAAM,QAAQ;EACnD,MAAM,OAAO,MAAM,OAAO,MAAM;EAChC,MAAM,QAAQ,KAAK,IAAI,IAAI,OAAO,SAAS,IAAI;EAC/C,MAAM,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,EAAE,CAAC,QAAQ,YAAY,KAAK,MAAM,IAAI;EAC3E,IAAI,MAAM,OAAO,MAAM,KAAK;GAAE;GAAM;GAAO;EAAI,CAAC;EAChD,aAAa,KAAK,SAAS;CAC7B;CACA,OAAO;AACT;AAEA,SAAS,UAAU,OAAsB;CACvC,MAAM,UAAU,MAAM,cAAc;CACpC,KAAK,MAAM,UAAU,QAAQ,iBAAiB,uBAAuB,GAAG,OAAO,OAAO;CACtF,OAAO,QAAQ,eAAe;AAChC;;AAGA,SAAgB,cAAc,SAA+B;CAC3D,MAAM,UAAU,QAAQ,KAAK,GAAG,EAAE;CAClC,OAAO,GAAG,UAAU,GAAG,QAAQ,OAAO,GAAG,GAAG,QAAQ,MAAM;AAC5D"}
|
|
@@ -38,12 +38,22 @@ export declare function locateSelection(root: Element, range: Range): QuoteLocat
|
|
|
38
38
|
/** A selection inside one rendered block as the words with the words around them; null when it spans blocks or is blank. */
|
|
39
39
|
export declare function captureTextQuote(root: Element, range: Range): TextQuote | null;
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* The rendered elements covering source lines `start`..`end`: each top-level
|
|
42
|
+
* block that overlaps them, or for a table only its rows on those lines.
|
|
43
|
+
*/
|
|
44
|
+
export declare function elementsInLines(root: Element, lines: {
|
|
45
|
+
start: number;
|
|
46
|
+
end: number;
|
|
47
|
+
}): Element[];
|
|
48
|
+
/**
|
|
49
|
+
* Finds a patch's quote again, searching only `within` (the rendered elements
|
|
50
|
+
* where the patch matches now, or the cell it was made in). The words with
|
|
43
51
|
* their context first, then with the context edited away; null once they are
|
|
44
52
|
* gone, or repeat so that nothing tells the occurrences apart, so the caller
|
|
45
53
|
* falls back to highlighting the lines.
|
|
46
54
|
*/
|
|
55
|
+
export declare function resolveQuoteWithin(within: readonly Element[], quote: TextQuote): Range | null;
|
|
56
|
+
/** `resolveQuoteWithin` the elements covering source lines `start`..`end`. */
|
|
47
57
|
export declare function resolveQuoteInLines(root: Element, lines: {
|
|
48
58
|
start: number;
|
|
49
59
|
end: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote-anchor.d.ts","sourceRoot":"","sources":["../../../src/file-findings/file-review/quote-anchor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"quote-anchor.d.ts","sourceRoot":"","sources":["../../../src/file-findings/file-review/quote-anchor.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAGjE,gGAAgG;AAChG,MAAM,MAAM,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7F,eAAO,MAAM,YAAY,OAAO,CAAC;AAI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,EAAE,SAAS,GAAG,KAAK,GAAG,IAAI,CAExH;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAEpF;AAED,8EAA8E;AAC9E,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC;AAoBtE;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,YAAY,GAAG,IAAI,CASpH;AAED,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,UAAU,EAAE,CAqBxG;AAQD,6DAA6D;AAC7D,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAG3D"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tableRows } from "./table-cell.js";
|
|
1
2
|
// src/file-findings/file-review/quote-anchor.ts
|
|
2
3
|
var QUOTE_PREFIX = "q:";
|
|
3
4
|
var SOURCE_BLOCK = "[data-source-start]";
|
|
@@ -166,17 +167,29 @@ var QUOTE_TIERS = [...TIERS, {
|
|
|
166
167
|
suffix: false
|
|
167
168
|
}];
|
|
168
169
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
170
|
+
* The rendered elements covering source lines `start`..`end`: each top-level
|
|
171
|
+
* block that overlaps them, or for a table only its rows on those lines.
|
|
172
|
+
*/
|
|
173
|
+
function elementsInLines(root, lines) {
|
|
174
|
+
return sections(root).flatMap(({ block }) => {
|
|
175
|
+
const { sourceStart, sourceEnd } = block.dataset;
|
|
176
|
+
if (Number(sourceStart) > lines.end || Number(sourceEnd) < lines.start) return [];
|
|
177
|
+
const rows = tableRows(block);
|
|
178
|
+
return rows.length > 0 ? rows.filter(({ line }) => line >= lines.start && line <= lines.end).map(({ row }) => row) : [block];
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Finds a patch's quote again, searching only `within` (the rendered elements
|
|
183
|
+
* where the patch matches now, or the cell it was made in). The words with
|
|
171
184
|
* their context first, then with the context edited away; null once they are
|
|
172
185
|
* gone, or repeat so that nothing tells the occurrences apart, so the caller
|
|
173
186
|
* falls back to highlighting the lines.
|
|
174
187
|
*/
|
|
175
|
-
function
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
});
|
|
188
|
+
function resolveQuoteWithin(within, quote) {
|
|
189
|
+
const candidates = within.map((block) => ({
|
|
190
|
+
block,
|
|
191
|
+
path: []
|
|
192
|
+
}));
|
|
180
193
|
const locator = {
|
|
181
194
|
path: [],
|
|
182
195
|
prefix: quote.prefix,
|
|
@@ -184,7 +197,7 @@ function resolveQuoteInLines(root, lines, quote) {
|
|
|
184
197
|
suffix: quote.suffix
|
|
185
198
|
};
|
|
186
199
|
for (const tier of QUOTE_TIERS) {
|
|
187
|
-
const found = matches(
|
|
200
|
+
const found = matches(candidates, locator, tier);
|
|
188
201
|
if (found.length === 1) return rangeIn(found[0].block, found[0].start, found[0].end);
|
|
189
202
|
if (found.length > 1) return null;
|
|
190
203
|
}
|
|
@@ -269,6 +282,6 @@ function describeQuote(locator) {
|
|
|
269
282
|
const section = locator.path.at(-1);
|
|
270
283
|
return `${section ? `${section} › ` : ""}“${locator.quote}”`;
|
|
271
284
|
}
|
|
272
|
-
export { QUOTE_PREFIX, captureTextQuote, describeQuote, locateSelection, locateSourceSelection, markdownOutline, parseQuoteAnchor, quoteAnchor, quoteLiesInLines, resolveQuote,
|
|
285
|
+
export { QUOTE_PREFIX, captureTextQuote, describeQuote, elementsInLines, locateSelection, locateSourceSelection, markdownOutline, parseQuoteAnchor, quoteAnchor, quoteLiesInLines, resolveQuote, resolveQuoteWithin, sourceSpans };
|
|
273
286
|
|
|
274
287
|
//# sourceMappingURL=quote-anchor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quote-anchor.js","names":[],"sources":["../../../src/file-findings/file-review/quote-anchor.ts"],"sourcesContent":["// Anchors on words inside rendered markdown, in the spirit of the W3C\n// TextQuoteSelector: a quote is found again through the heading outline (the\n// section it sits in) plus a few words on each side, so the same words\n// elsewhere — or edits to other sections — never move it.\nimport type { TextQuote } from \"../../comments/annotation-types\";\n\n/** A quote inside the section named by `path` (its heading trail), with the words around it. */\nexport type QuoteLocator = { path: string[]; prefix: string; quote: string; suffix: string };\n\nexport const QUOTE_PREFIX = \"q:\";\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\nconst HEADING = /^h([1-6])$/;\n/** Heading text kept in a path; longer headings are cut so stored anchors stay bounded. */\nexport const OUTLINE_HEADING_LIMIT = 200;\n/** Context words taken on each side to start with; grown until the anchor is unique. */\nconst MIN_CONTEXT_WORDS = 2;\n\nexport function quoteAnchor(locator: QuoteLocator): string {\n return `${QUOTE_PREFIX}${JSON.stringify([locator.path, locator.prefix, locator.quote, locator.suffix])}`;\n}\n\n/** The locator a `q:` anchor encodes; throws for a malformed one. */\nexport function parseQuoteAnchor(anchor: string): QuoteLocator {\n if (!anchor.startsWith(QUOTE_PREFIX)) throw new Error(`not a quote anchor: ${JSON.stringify(anchor)}`);\n const parsed: unknown = JSON.parse(anchor.slice(QUOTE_PREFIX.length));\n const [path, prefix, quote, suffix] = Array.isArray(parsed) ? parsed : [];\n if (\n !Array.isArray(path) ||\n !path.every((heading) => typeof heading === \"string\") ||\n typeof prefix !== \"string\" ||\n typeof quote !== \"string\" ||\n typeof suffix !== \"string\"\n ) {\n throw new Error(`malformed quote anchor ${JSON.stringify(anchor)}`);\n }\n return { path, prefix, quote, suffix };\n}\n\n/** A top-level rendered block, the heading trail it sits under, and its first source line. */\nexport type OutlineEntry = { block: Element; path: string[]; line: number };\n\n/**\n * Every top-level block of rendered markdown (`Markdown sourceBlocks`) in\n * document order, with the headings above it: its table-of-contents path.\n */\nexport function markdownOutline(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 const text = blockText(block).replace(/\\s+/g, \" \").trim().slice(0, OUTLINE_HEADING_LIMIT);\n stack.push({ level: Number(level), text });\n }\n return { block, path: stack.map((heading) => heading.text), line: Number((block as HTMLElement).dataset.sourceStart) };\n });\n}\n\ntype Section = Pick<OutlineEntry, \"block\" | \"path\">;\n\nconst sections = (root: Element): Section[] => markdownOutline(root);\n\nfunction textNodes(block: Element): Text[] {\n const walker = document.createTreeWalker(block, NodeFilter.SHOW_TEXT);\n const nodes: Text[] = [];\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (!node.parentElement?.closest(\"[data-comment-author]\")) nodes.push(node as Text);\n }\n return nodes;\n}\n\n/** A block's text exactly as its text nodes concatenate, so offsets map back onto them. */\nfunction blockText(block: Element): string {\n return textNodes(block)\n .map((node) => node.data)\n .join(\"\");\n}\n\nfunction rangeIn(block: Element, start: number, end: number): Range {\n const range = document.createRange();\n let offset = 0;\n let started = false;\n for (const node of textNodes(block)) {\n if (!started && start < offset + node.length) {\n range.setStart(node, start - offset);\n started = true;\n }\n if (started && end <= offset + node.length) {\n range.setEnd(node, end - offset);\n return range;\n }\n offset += node.length;\n }\n throw new Error(`quote-anchor: offsets ${start}-${end} lie outside the block`);\n}\n\n// Rendered cells and list items concatenate without whitespace (\"lead5 min\"),\n// so any run of whitespace in the locator matches zero or more in the text.\nfunction pattern(text: string): string {\n return text\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((word) => word.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n .join(\"\\\\s*\");\n}\n\ntype Match = { block: Element; start: number; end: number };\n\nfunction matches(candidates: readonly Section[], locator: QuoteLocator, context: { prefix: boolean; suffix: boolean }): Match[] {\n const before = context.prefix && locator.prefix.trim() ? `(?<=${pattern(locator.prefix)}\\\\s*)` : \"\";\n const after = context.suffix && locator.suffix.trim() ? `(?=\\\\s*${pattern(locator.suffix)})` : \"\";\n const regex = new RegExp(`${before}${pattern(locator.quote)}${after}`, \"g\");\n return candidates.flatMap(({ block }) =>\n [...blockText(block).matchAll(regex)].map((m) => ({ block, start: m.index, end: m.index + m[0].length })),\n );\n}\n\nconst samePath = (a: readonly string[], b: readonly string[]) => a.length === b.length && a.every((h, i) => h === b[i]);\n\n// Strictest first. A looser tier is tried only when a stricter one finds\n// nothing, so edited context still resolves, but never guesses between two.\nconst TIERS = [\n { prefix: true, suffix: true },\n { prefix: true, suffix: false },\n { prefix: false, suffix: true },\n] as const;\n\n/**\n * Finds a quote again: in its section by quote plus context, then with one\n * side of the context edited away; failing that (a renamed heading), anywhere\n * by the full context. Null when it is gone or ambiguous.\n */\nexport function resolveQuote(root: Element, locator: QuoteLocator): Range | null {\n const all = sections(root);\n const section = all.filter((s) => samePath(s.path, locator.path));\n for (const tier of TIERS) {\n const found = matches(section, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n }\n const relocated = matches(all, locator, TIERS[0]);\n return relocated.length === 1 ? rangeIn(relocated[0]!.block, relocated[0]!.start, relocated[0]!.end) : null;\n}\n\n/**\n * The locator for a selection inside one block, with just enough context on\n * each side to make it unique in its section. Null when the selection spans\n * blocks, is blank, or repeats so exactly that no context tells it apart.\n */\nexport function locateSelection(root: Element, range: Range): QuoteLocator | null {\n const all = sections(root);\n const own = all.find(({ block }) => block.contains(range.startContainer) && block.contains(range.endContainer));\n if (!own) return null;\n const text = blockText(own.block);\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const raw = rangeText(range);\n const start = rangeText(lead).length + (raw.length - raw.trimStart().length);\n const end = rangeText(lead).length + raw.trimEnd().length;\n if (end <= start) return null;\n\n const before = text.slice(0, start).split(/\\s+/).filter(Boolean);\n const after = text.slice(end).split(/\\s+/).filter(Boolean);\n const section = all.filter((s) => samePath(s.path, own.path));\n for (let words = MIN_CONTEXT_WORDS; ; words++) {\n const locator = {\n path: own.path,\n prefix: before.slice(-words).join(\" \"),\n quote: text.slice(start, end),\n suffix: after.slice(0, words).join(\" \"),\n };\n const found = matches(section, locator, TIERS[0]);\n if (found.length === 1 && found[0]!.block === own.block && found[0]!.start === start) return locator;\n if (words >= before.length && words >= after.length) return null;\n }\n}\n\n/** A selection inside one rendered block as the words with the words around them; null when it spans blocks or is blank. */\nexport function captureTextQuote(root: Element, range: Range): TextQuote | null {\n const locator = locateSelection(root, range);\n return locator && { prefix: locator.prefix, exact: locator.quote, suffix: locator.suffix };\n}\n\n/** Context from the strictest tier to none at all: inside a patch's few lines the words alone may be enough. */\nconst QUOTE_TIERS = [...TIERS, { prefix: false, suffix: false }] as const;\n\n/**\n * Finds a patch's quote again, searching only the rendered blocks that cover\n * source lines `start`..`end` (where the patch matches now). The words with\n * their context first, then with the context edited away; null once they are\n * gone, or repeat so that nothing tells the occurrences apart, so the caller\n * falls back to highlighting the lines.\n */\nexport function resolveQuoteInLines(root: Element, lines: { start: number; end: number }, quote: TextQuote): Range | null {\n const covering = sections(root).filter(({ block }) => {\n const { sourceStart, sourceEnd } = (block as HTMLElement).dataset;\n return Number(sourceStart) <= lines.end && Number(sourceEnd) >= lines.start;\n });\n const locator = { path: [], prefix: quote.prefix, quote: quote.exact, suffix: quote.suffix };\n for (const tier of QUOTE_TIERS) {\n const found = matches(covering, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n if (found.length > 1) return null;\n }\n return null;\n}\n\n/**\n * Whether the quote's exact text appears verbatim in the markdown source `lines`:\n * the rule the server enforces on a selector's quote. Rendered text that\n * differs from its source (`**bold**`, links, escapes) therefore does not lie\n * in the lines, and the patch alone anchors the thread.\n */\nexport function quoteLiesInLines(quote: TextQuote, lines: readonly string[]): boolean {\n return quote.exact !== \"\" && lines.join(\"\\n\").includes(quote.exact);\n}\n\n/** A run of characters on one source line (1-based line, 0-based columns). */\nexport type SourceSpan = { line: number; start: number; end: number };\n\n// Markdown markup that renders as nothing (emphasis, code ticks, table pipes,\n// quote and heading markers, list bullets), so it may sit between source words.\nconst MARKUP = /[*_`|>#~]|(?:^|\\s)[-+](?=\\s)/g;\n\nfunction sourcePattern(quote: string): string {\n return pattern(quote.replace(MARKUP, \" \")).replaceAll(\"\\\\s*\", \"[\\\\s*_`|>#~]*\");\n}\n\nfunction sourceBlocks(root: Element, lines: readonly string[]) {\n return sections(root).map(({ block }) => {\n const first = Number((block as HTMLElement).dataset.sourceStart);\n const last = Number((block as HTMLElement).dataset.sourceEnd);\n return { block, first, last, text: lines.slice(first - 1, last).join(\"\\n\") };\n });\n}\n\nconst allMatches = (text: string, source: string) => [...text.matchAll(new RegExp(source, \"g\"))];\n\n/**\n * The quote locator for a selection in the raw markdown: the selection's words\n * are found in the rendered block built from that line, as the same occurrence\n * they are in the source, so a comment made in Source shows in Preview too.\n * Null when the selection is only markup or its block renders no such words.\n */\nexport function locateSourceSelection(root: Element, lines: readonly string[], span: SourceSpan): QuoteLocator | null {\n const selected = lines[span.line - 1]?.slice(span.start, span.end) ?? \"\";\n if (!selected.replace(MARKUP, \" \").trim()) return null;\n const own = sourceBlocks(root, lines).find((b) => span.line >= b.first && span.line <= b.last);\n if (!own) return null;\n const at = lines.slice(own.first - 1, span.line - 1).reduce((sum, l) => sum + l.length + 1, 0) + span.start;\n const k = allMatches(own.text, sourcePattern(selected)).findIndex((m) => m.index + m[0].length > at && m.index < at + selected.length);\n const hit = k < 0 ? undefined : allMatches(blockText(own.block), pattern(selected.replace(MARKUP, \" \")))[k];\n return hit ? locateSelection(root, rangeIn(own.block, hit.index, hit.index + hit[0].length)) : null;\n}\n\n/** Where a quote anchor's text sits in the raw markdown, one span per source line it covers. */\nexport function sourceSpans(root: Element, lines: readonly string[], locator: QuoteLocator): SourceSpan[] {\n const range = resolveQuote(root, locator);\n const own = range && sourceBlocks(root, lines).find(({ block }) => block.contains(range.startContainer));\n if (!range || !own) return [];\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const offset = rangeText(lead).length;\n const k = allMatches(blockText(own.block), pattern(locator.quote)).findIndex((m) => m.index === offset);\n const hit = k < 0 ? undefined : allMatches(own.text, sourcePattern(locator.quote))[k];\n if (!hit) return [];\n const spans: SourceSpan[] = [];\n let lineStart = 0;\n for (let line = own.first; line <= own.last; line++) {\n const text = lines[line - 1] ?? \"\";\n const start = Math.max(hit.index, lineStart) - lineStart;\n const end = Math.min(hit.index + hit[0].length, lineStart + text.length) - lineStart;\n if (end > start) spans.push({ line, start, end });\n lineStart += text.length + 1;\n }\n return spans;\n}\n\nfunction rangeText(range: Range): string {\n const content = range.cloneContents();\n for (const avatar of content.querySelectorAll(\"[data-comment-author]\")) avatar.remove();\n return content.textContent ?? \"\";\n}\n\n/** Reader-facing label: the section and the quoted words. */\nexport function describeQuote(locator: QuoteLocator): string {\n const section = locator.path.at(-1);\n return `${section ? `${section} › ` : \"\"}“${locator.quote}”`;\n}\n"],"mappings":";AASA,IAAa,eAAe;AAE5B,IAAM,eAAe;AACrB,IAAM,UAAU;;AAIhB,IAAM,oBAAoB;AAE1B,SAAgB,YAAY,SAA+B;CACzD,OAAO,KAAkB,KAAK,UAAU;EAAC,QAAQ;EAAM,QAAQ;EAAQ,QAAQ;EAAO,QAAQ;CAAM,CAAC;AACvG;;AAGA,SAAgB,iBAAiB,QAA8B;CAC7D,IAAI,CAAC,OAAO,WAAA,IAAuB,GAAG,MAAM,IAAI,MAAM,uBAAuB,KAAK,U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MAAM,gBAAgB,MAAM,WAAW;CACnD,MAAM,SAAS,UAAU,IAAI,CAAC,CAAC;CAC/B,MAAM,IAAI,WAAW,UAAU,IAAI,KAAK,GAAG,QAAQ,QAAQ,KAAK,CAAC,CAAC,CAAC,WAAW,MAAM,EAAE,UAAU,MAAM;CACtG,MAAM,MAAM,IAAI,IAAI,KAAA,IAAY,WAAW,IAAI,MAAM,cAAc,QAAQ,KAAK,CAAC,CAAC,CAAC;CACnF,IAAI,CAAC,KAAK,OAAO,CAAC;CAClB,MAAM,QAAsB,CAAC;CAC7B,IAAI,YAAY;CAChB,KAAK,IAAI,OAAO,IAAI,OAAO,QAAQ,IAAI,MAAM,QAAQ;EACnD,MAAM,OAAO,MAAM,OAAO,MAAM;EAChC,MAAM,QAAQ,KAAK,IAAI,IAAI,OAAO,SAAS,IAAI;EAC/C,MAAM,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,EAAE,CAAC,QAAQ,YAAY,KAAK,MAAM,IAAI;EAC3E,IAAI,MAAM,OAAO,MAAM,KAAK;GAAE;GAAM;GAAO;EAAI,CAAC;EAChD,aAAa,KAAK,SAAS;CAC7B;CACA,OAAO;AACT;AAEA,SAAS,UAAU,OAAsB;CACvC,MAAM,UAAU,MAAM,cAAc;CACpC,KAAK,MAAM,UAAU,QAAQ,iBAAiB,uBAAuB,GAAG,OAAO,OAAO;CACtF,OAAO,QAAQ,eAAe;AAChC;;AAGA,SAAgB,cAAc,SAA+B;CAC3D,MAAM,UAAU,QAAQ,KAAK,GAAG,EAAE;CAClC,OAAO,GAAG,UAAU,GAAG,QAAQ,OAAO,GAAG,GAAG,QAAQ,MAAM;AAC5D"}
|
|
1
|
+
{"version":3,"file":"quote-anchor.js","names":[],"sources":["../../../src/file-findings/file-review/quote-anchor.ts"],"sourcesContent":["// Anchors on words inside rendered markdown, in the spirit of the W3C\n// TextQuoteSelector: a quote is found again through the heading outline (the\n// section it sits in) plus a few words on each side, so the same words\n// elsewhere — or edits to other sections — never move it.\nimport type { TextQuote } from \"../../comments/annotation-types\";\nimport { tableRows } from \"./table-cell\";\n\n/** A quote inside the section named by `path` (its heading trail), with the words around it. */\nexport type QuoteLocator = { path: string[]; prefix: string; quote: string; suffix: string };\n\nexport const QUOTE_PREFIX = \"q:\";\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\nconst HEADING = /^h([1-6])$/;\n/** Heading text kept in a path; longer headings are cut so stored anchors stay bounded. */\nexport const OUTLINE_HEADING_LIMIT = 200;\n/** Context words taken on each side to start with; grown until the anchor is unique. */\nconst MIN_CONTEXT_WORDS = 2;\n\nexport function quoteAnchor(locator: QuoteLocator): string {\n return `${QUOTE_PREFIX}${JSON.stringify([locator.path, locator.prefix, locator.quote, locator.suffix])}`;\n}\n\n/** The locator a `q:` anchor encodes; throws for a malformed one. */\nexport function parseQuoteAnchor(anchor: string): QuoteLocator {\n if (!anchor.startsWith(QUOTE_PREFIX)) throw new Error(`not a quote anchor: ${JSON.stringify(anchor)}`);\n const parsed: unknown = JSON.parse(anchor.slice(QUOTE_PREFIX.length));\n const [path, prefix, quote, suffix] = Array.isArray(parsed) ? parsed : [];\n if (\n !Array.isArray(path) ||\n !path.every((heading) => typeof heading === \"string\") ||\n typeof prefix !== \"string\" ||\n typeof quote !== \"string\" ||\n typeof suffix !== \"string\"\n ) {\n throw new Error(`malformed quote anchor ${JSON.stringify(anchor)}`);\n }\n return { path, prefix, quote, suffix };\n}\n\n/** A top-level rendered block, the heading trail it sits under, and its first source line. */\nexport type OutlineEntry = { block: Element; path: string[]; line: number };\n\n/**\n * Every top-level block of rendered markdown (`Markdown sourceBlocks`) in\n * document order, with the headings above it: its table-of-contents path.\n */\nexport function markdownOutline(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 const text = blockText(block).replace(/\\s+/g, \" \").trim().slice(0, OUTLINE_HEADING_LIMIT);\n stack.push({ level: Number(level), text });\n }\n return { block, path: stack.map((heading) => heading.text), line: Number((block as HTMLElement).dataset.sourceStart) };\n });\n}\n\ntype Section = Pick<OutlineEntry, \"block\" | \"path\">;\n\nconst sections = (root: Element): Section[] => markdownOutline(root);\n\nfunction textNodes(block: Element): Text[] {\n const walker = document.createTreeWalker(block, NodeFilter.SHOW_TEXT);\n const nodes: Text[] = [];\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (!node.parentElement?.closest(\"[data-comment-author]\")) nodes.push(node as Text);\n }\n return nodes;\n}\n\n/** A block's text exactly as its text nodes concatenate, so offsets map back onto them. */\nfunction blockText(block: Element): string {\n return textNodes(block)\n .map((node) => node.data)\n .join(\"\");\n}\n\nfunction rangeIn(block: Element, start: number, end: number): Range {\n const range = document.createRange();\n let offset = 0;\n let started = false;\n for (const node of textNodes(block)) {\n if (!started && start < offset + node.length) {\n range.setStart(node, start - offset);\n started = true;\n }\n if (started && end <= offset + node.length) {\n range.setEnd(node, end - offset);\n return range;\n }\n offset += node.length;\n }\n throw new Error(`quote-anchor: offsets ${start}-${end} lie outside the block`);\n}\n\n// Rendered cells and list items concatenate without whitespace (\"lead5 min\"),\n// so any run of whitespace in the locator matches zero or more in the text.\nfunction pattern(text: string): string {\n return text\n .trim()\n .split(/\\s+/)\n .filter(Boolean)\n .map((word) => word.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\"))\n .join(\"\\\\s*\");\n}\n\ntype Match = { block: Element; start: number; end: number };\n\nfunction matches(candidates: readonly Section[], locator: QuoteLocator, context: { prefix: boolean; suffix: boolean }): Match[] {\n const before = context.prefix && locator.prefix.trim() ? `(?<=${pattern(locator.prefix)}\\\\s*)` : \"\";\n const after = context.suffix && locator.suffix.trim() ? `(?=\\\\s*${pattern(locator.suffix)})` : \"\";\n const regex = new RegExp(`${before}${pattern(locator.quote)}${after}`, \"g\");\n return candidates.flatMap(({ block }) =>\n [...blockText(block).matchAll(regex)].map((m) => ({ block, start: m.index, end: m.index + m[0].length })),\n );\n}\n\nconst samePath = (a: readonly string[], b: readonly string[]) => a.length === b.length && a.every((h, i) => h === b[i]);\n\n// Strictest first. A looser tier is tried only when a stricter one finds\n// nothing, so edited context still resolves, but never guesses between two.\nconst TIERS = [\n { prefix: true, suffix: true },\n { prefix: true, suffix: false },\n { prefix: false, suffix: true },\n] as const;\n\n/**\n * Finds a quote again: in its section by quote plus context, then with one\n * side of the context edited away; failing that (a renamed heading), anywhere\n * by the full context. Null when it is gone or ambiguous.\n */\nexport function resolveQuote(root: Element, locator: QuoteLocator): Range | null {\n const all = sections(root);\n const section = all.filter((s) => samePath(s.path, locator.path));\n for (const tier of TIERS) {\n const found = matches(section, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n }\n const relocated = matches(all, locator, TIERS[0]);\n return relocated.length === 1 ? rangeIn(relocated[0]!.block, relocated[0]!.start, relocated[0]!.end) : null;\n}\n\n/**\n * The locator for a selection inside one block, with just enough context on\n * each side to make it unique in its section. Null when the selection spans\n * blocks, is blank, or repeats so exactly that no context tells it apart.\n */\nexport function locateSelection(root: Element, range: Range): QuoteLocator | null {\n const all = sections(root);\n const own = all.find(({ block }) => block.contains(range.startContainer) && block.contains(range.endContainer));\n if (!own) return null;\n const text = blockText(own.block);\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const raw = rangeText(range);\n const start = rangeText(lead).length + (raw.length - raw.trimStart().length);\n const end = rangeText(lead).length + raw.trimEnd().length;\n if (end <= start) return null;\n\n const before = text.slice(0, start).split(/\\s+/).filter(Boolean);\n const after = text.slice(end).split(/\\s+/).filter(Boolean);\n const section = all.filter((s) => samePath(s.path, own.path));\n for (let words = MIN_CONTEXT_WORDS; ; words++) {\n const locator = {\n path: own.path,\n prefix: before.slice(-words).join(\" \"),\n quote: text.slice(start, end),\n suffix: after.slice(0, words).join(\" \"),\n };\n const found = matches(section, locator, TIERS[0]);\n if (found.length === 1 && found[0]!.block === own.block && found[0]!.start === start) return locator;\n if (words >= before.length && words >= after.length) return null;\n }\n}\n\n/** A selection inside one rendered block as the words with the words around them; null when it spans blocks or is blank. */\nexport function captureTextQuote(root: Element, range: Range): TextQuote | null {\n const locator = locateSelection(root, range);\n return locator && { prefix: locator.prefix, exact: locator.quote, suffix: locator.suffix };\n}\n\n/** Context from the strictest tier to none at all: inside a patch's few lines the words alone may be enough. */\nconst QUOTE_TIERS = [...TIERS, { prefix: false, suffix: false }] as const;\n\n/**\n * The rendered elements covering source lines `start`..`end`: each top-level\n * block that overlaps them, or for a table only its rows on those lines.\n */\nexport function elementsInLines(root: Element, lines: { start: number; end: number }): Element[] {\n return sections(root).flatMap(({ block }) => {\n const { sourceStart, sourceEnd } = (block as HTMLElement).dataset;\n if (Number(sourceStart) > lines.end || Number(sourceEnd) < lines.start) return [];\n const rows = tableRows(block);\n return rows.length > 0 ? rows.filter(({ line }) => line >= lines.start && line <= lines.end).map(({ row }) => row) : [block];\n });\n}\n\n/**\n * Finds a patch's quote again, searching only `within` (the rendered elements\n * where the patch matches now, or the cell it was made in). The words with\n * their context first, then with the context edited away; null once they are\n * gone, or repeat so that nothing tells the occurrences apart, so the caller\n * falls back to highlighting the lines.\n */\nexport function resolveQuoteWithin(within: readonly Element[], quote: TextQuote): Range | null {\n const candidates = within.map((block) => ({ block, path: [] }));\n const locator = { path: [], prefix: quote.prefix, quote: quote.exact, suffix: quote.suffix };\n for (const tier of QUOTE_TIERS) {\n const found = matches(candidates, locator, tier);\n if (found.length === 1) return rangeIn(found[0]!.block, found[0]!.start, found[0]!.end);\n if (found.length > 1) return null;\n }\n return null;\n}\n\n/** `resolveQuoteWithin` the elements covering source lines `start`..`end`. */\nexport function resolveQuoteInLines(root: Element, lines: { start: number; end: number }, quote: TextQuote): Range | null {\n return resolveQuoteWithin(elementsInLines(root, lines), quote);\n}\n\n/**\n * Whether the quote's exact text appears verbatim in the markdown source `lines`:\n * the rule the server enforces on a selector's quote. Rendered text that\n * differs from its source (`**bold**`, links, escapes) therefore does not lie\n * in the lines, and the patch alone anchors the thread.\n */\nexport function quoteLiesInLines(quote: TextQuote, lines: readonly string[]): boolean {\n return quote.exact !== \"\" && lines.join(\"\\n\").includes(quote.exact);\n}\n\n/** A run of characters on one source line (1-based line, 0-based columns). */\nexport type SourceSpan = { line: number; start: number; end: number };\n\n// Markdown markup that renders as nothing (emphasis, code ticks, table pipes,\n// quote and heading markers, list bullets), so it may sit between source words.\nconst MARKUP = /[*_`|>#~]|(?:^|\\s)[-+](?=\\s)/g;\n\nfunction sourcePattern(quote: string): string {\n return pattern(quote.replace(MARKUP, \" \")).replaceAll(\"\\\\s*\", \"[\\\\s*_`|>#~]*\");\n}\n\nfunction sourceBlocks(root: Element, lines: readonly string[]) {\n return sections(root).map(({ block }) => {\n const first = Number((block as HTMLElement).dataset.sourceStart);\n const last = Number((block as HTMLElement).dataset.sourceEnd);\n return { block, first, last, text: lines.slice(first - 1, last).join(\"\\n\") };\n });\n}\n\nconst allMatches = (text: string, source: string) => [...text.matchAll(new RegExp(source, \"g\"))];\n\n/**\n * The quote locator for a selection in the raw markdown: the selection's words\n * are found in the rendered block built from that line, as the same occurrence\n * they are in the source, so a comment made in Source shows in Preview too.\n * Null when the selection is only markup or its block renders no such words.\n */\nexport function locateSourceSelection(root: Element, lines: readonly string[], span: SourceSpan): QuoteLocator | null {\n const selected = lines[span.line - 1]?.slice(span.start, span.end) ?? \"\";\n if (!selected.replace(MARKUP, \" \").trim()) return null;\n const own = sourceBlocks(root, lines).find((b) => span.line >= b.first && span.line <= b.last);\n if (!own) return null;\n const at = lines.slice(own.first - 1, span.line - 1).reduce((sum, l) => sum + l.length + 1, 0) + span.start;\n const k = allMatches(own.text, sourcePattern(selected)).findIndex((m) => m.index + m[0].length > at && m.index < at + selected.length);\n const hit = k < 0 ? undefined : allMatches(blockText(own.block), pattern(selected.replace(MARKUP, \" \")))[k];\n return hit ? locateSelection(root, rangeIn(own.block, hit.index, hit.index + hit[0].length)) : null;\n}\n\n/** Where a quote anchor's text sits in the raw markdown, one span per source line it covers. */\nexport function sourceSpans(root: Element, lines: readonly string[], locator: QuoteLocator): SourceSpan[] {\n const range = resolveQuote(root, locator);\n const own = range && sourceBlocks(root, lines).find(({ block }) => block.contains(range.startContainer));\n if (!range || !own) return [];\n const lead = document.createRange();\n lead.setStart(own.block, 0);\n lead.setEnd(range.startContainer, range.startOffset);\n const offset = rangeText(lead).length;\n const k = allMatches(blockText(own.block), pattern(locator.quote)).findIndex((m) => m.index === offset);\n const hit = k < 0 ? undefined : allMatches(own.text, sourcePattern(locator.quote))[k];\n if (!hit) return [];\n const spans: SourceSpan[] = [];\n let lineStart = 0;\n for (let line = own.first; line <= own.last; line++) {\n const text = lines[line - 1] ?? \"\";\n const start = Math.max(hit.index, lineStart) - lineStart;\n const end = Math.min(hit.index + hit[0].length, lineStart + text.length) - lineStart;\n if (end > start) spans.push({ line, start, end });\n lineStart += text.length + 1;\n }\n return spans;\n}\n\nfunction rangeText(range: Range): string {\n const content = range.cloneContents();\n for (const avatar of content.querySelectorAll(\"[data-comment-author]\")) avatar.remove();\n return content.textContent ?? \"\";\n}\n\n/** Reader-facing label: the section and the quoted words. */\nexport function describeQuote(locator: QuoteLocator): string {\n const section = locator.path.at(-1);\n return `${section ? `${section} › ` : \"\"}“${locator.quote}”`;\n}\n"],"mappings":";;AAUA,IAAa,eAAe;AAE5B,IAAM,eAAe;AACrB,IAAM,UAAU;;AAIhB,IAAM,oBAAoB;AAE1B,SAAgB,YAAY,SAA+B;CACzD,OAAO,KAAkB,KAAK,UAAU;EAAC,QAAQ;EAAM,QAAQ;EAAQ,QAAQ;EAAO,QAAQ;CAAM,CAAC;AACvG;;AAGA,SAAgB,iBAAiB,QAA8B;CAC7D,IAAI,CAAC,OAAO,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;AAChC;;AAGA,SAAgB,cAAc,SAA+B;CAC3D,MAAM,UAAU,QAAQ,KAAK,GAAG,EAAE;CAClC,OAAO,GAAG,UAAU,GAAG,QAAQ,OAAO,GAAG,GAAG,QAAQ,MAAM;AAC5D"}
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
const require_source_marks = require("./source-marks.cjs");
|
|
2
|
+
const require_table_cell = require("./table-cell.cjs");
|
|
2
3
|
// src/file-findings/file-review/selection-lines.ts
|
|
3
4
|
var SOURCE_BLOCK = "[data-source-start]";
|
|
5
|
+
/** Whether `range` covers some of `node`'s contents, not merely reaching its edge. */
|
|
6
|
+
function touches(range, node) {
|
|
7
|
+
const own = document.createRange();
|
|
8
|
+
own.selectNodeContents(node);
|
|
9
|
+
return range.compareBoundaryPoints(Range.END_TO_START, own) < 0 && range.compareBoundaryPoints(Range.START_TO_END, own) > 0;
|
|
10
|
+
}
|
|
4
11
|
/**
|
|
5
12
|
* The source lines of the rendered blocks (`Markdown sourceBlocks`) a
|
|
6
13
|
* selection in Preview touches, from the first block's start to the last
|
|
7
|
-
* block's end
|
|
8
|
-
* cover it. Null when it
|
|
14
|
+
* block's end; in a table, only the lines of the rows it touches. A selection
|
|
15
|
+
* that merely reaches the edge of a block does not cover it. Null when it
|
|
16
|
+
* touches no block.
|
|
9
17
|
*/
|
|
10
18
|
function previewSelectionLines(range, markdown) {
|
|
11
19
|
const covered = [];
|
|
12
20
|
for (const block of markdown.querySelectorAll(SOURCE_BLOCK)) {
|
|
13
|
-
if (block.parentElement?.closest(SOURCE_BLOCK)) continue;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
if (block.parentElement?.closest(SOURCE_BLOCK) || !touches(range, block)) continue;
|
|
22
|
+
const rows = require_table_cell.tableRows(block).filter(({ row }) => touches(range, row));
|
|
23
|
+
if (rows.length > 0) covered.push(...rows.map(({ line }) => ({
|
|
24
|
+
startLine: line,
|
|
25
|
+
endLine: line
|
|
26
|
+
})));
|
|
27
|
+
else covered.push({
|
|
19
28
|
startLine: Number(block.dataset.sourceStart),
|
|
20
29
|
endLine: Number(block.dataset.sourceEnd)
|
|
21
30
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection-lines.cjs","names":["sourceRangeOf"],"sources":["../../../src/file-findings/file-review/selection-lines.ts"],"sourcesContent":["import { sourceRangeOf } from \"./source-marks\";\n\n/** An inclusive, 1-based range of source lines. */\nexport type LineRange = { startLine: number; endLine: number };\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\n\n/**\n * The source lines of the rendered blocks (`Markdown sourceBlocks`) a\n * selection in Preview touches, from the first block's start to the last\n * block's end. A selection that merely reaches the edge of a block does not
|
|
1
|
+
{"version":3,"file":"selection-lines.cjs","names":["tableRows","sourceRangeOf"],"sources":["../../../src/file-findings/file-review/selection-lines.ts"],"sourcesContent":["import { sourceRangeOf } from \"./source-marks\";\nimport { tableRows } from \"./table-cell\";\n\n/** An inclusive, 1-based range of source lines. */\nexport type LineRange = { startLine: number; endLine: number };\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\n\n/** Whether `range` covers some of `node`'s contents, not merely reaching its edge. */\nfunction touches(range: Range, node: Node): boolean {\n const own = document.createRange();\n own.selectNodeContents(node);\n return range.compareBoundaryPoints(Range.END_TO_START, own) < 0 && range.compareBoundaryPoints(Range.START_TO_END, own) > 0;\n}\n\n/**\n * The source lines of the rendered blocks (`Markdown sourceBlocks`) a\n * selection in Preview touches, from the first block's start to the last\n * block's end; in a table, only the lines of the rows it touches. A selection\n * that merely reaches the edge of a block does not cover it. Null when it\n * touches no block.\n */\nexport function previewSelectionLines(range: Range, markdown: Element): LineRange | null {\n const covered: LineRange[] = [];\n for (const block of markdown.querySelectorAll<HTMLElement>(SOURCE_BLOCK)) {\n if (block.parentElement?.closest(SOURCE_BLOCK) || !touches(range, block)) continue;\n const rows = tableRows(block).filter(({ row }) => touches(range, row));\n if (rows.length > 0) covered.push(...rows.map(({ line }) => ({ startLine: line, endLine: line })));\n else covered.push({ startLine: Number(block.dataset.sourceStart), endLine: Number(block.dataset.sourceEnd) });\n }\n if (covered.length === 0) return null;\n return {\n startLine: Math.min(...covered.map((block) => block.startLine)),\n endLine: Math.max(...covered.map((block) => block.endLine)),\n };\n}\n\n/**\n * The source lines a selection in the Source listing covers. A selection that\n * ends at the very start of a later line does not include that line. Null when\n * either end is outside the lines' text.\n */\nexport function sourceSelectionLines(range: Range): LineRange | null {\n const covered = sourceRangeOf(range);\n if (!covered) return null;\n const { start, end } = covered;\n const endLine = end.column === 0 && end.line > start.line ? end.line - 1 : end.line;\n return { startLine: start.line, endLine };\n}\n"],"mappings":";;;AAMA,IAAM,eAAe;;AAGrB,SAAS,QAAQ,OAAc,MAAqB;CAClD,MAAM,MAAM,SAAS,YAAY;CACjC,IAAI,mBAAmB,IAAI;CAC3B,OAAO,MAAM,sBAAsB,MAAM,cAAc,GAAG,IAAI,KAAK,MAAM,sBAAsB,MAAM,cAAc,GAAG,IAAI;AAC5H;;;;;;;;AASA,SAAgB,sBAAsB,OAAc,UAAqC;CACvF,MAAM,UAAuB,CAAC;CAC9B,KAAK,MAAM,SAAS,SAAS,iBAA8B,YAAY,GAAG;EACxE,IAAI,MAAM,eAAe,QAAQ,YAAY,KAAK,CAAC,QAAQ,OAAO,KAAK,GAAG;EAC1E,MAAM,OAAOA,mBAAAA,UAAU,KAAK,CAAC,CAAC,QAAQ,EAAE,UAAU,QAAQ,OAAO,GAAG,CAAC;EACrE,IAAI,KAAK,SAAS,GAAG,QAAQ,KAAK,GAAG,KAAK,KAAK,EAAE,YAAY;GAAE,WAAW;GAAM,SAAS;EAAK,EAAE,CAAC;OAC5F,QAAQ,KAAK;GAAE,WAAW,OAAO,MAAM,QAAQ,WAAW;GAAG,SAAS,OAAO,MAAM,QAAQ,SAAS;EAAE,CAAC;CAC9G;CACA,IAAI,QAAQ,WAAW,GAAG,OAAO;CACjC,OAAO;EACL,WAAW,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,SAAS,CAAC;EAC9D,SAAS,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,OAAO,CAAC;CAC5D;AACF;;;;;;AAOA,SAAgB,qBAAqB,OAAgC;CACnE,MAAM,UAAUC,qBAAAA,cAAc,KAAK;CACnC,IAAI,CAAC,SAAS,OAAO;CACrB,MAAM,EAAE,OAAO,QAAQ;CACvB,MAAM,UAAU,IAAI,WAAW,KAAK,IAAI,OAAO,MAAM,OAAO,IAAI,OAAO,IAAI,IAAI;CAC/E,OAAO;EAAE,WAAW,MAAM;EAAM;CAAQ;AAC1C"}
|
|
@@ -6,8 +6,9 @@ export type LineRange = {
|
|
|
6
6
|
/**
|
|
7
7
|
* The source lines of the rendered blocks (`Markdown sourceBlocks`) a
|
|
8
8
|
* selection in Preview touches, from the first block's start to the last
|
|
9
|
-
* block's end
|
|
10
|
-
* cover it. Null when it
|
|
9
|
+
* block's end; in a table, only the lines of the rows it touches. A selection
|
|
10
|
+
* that merely reaches the edge of a block does not cover it. Null when it
|
|
11
|
+
* touches no block.
|
|
11
12
|
*/
|
|
12
13
|
export declare function previewSelectionLines(range: Range, markdown: Element): LineRange | null;
|
|
13
14
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection-lines.d.ts","sourceRoot":"","sources":["../../../src/file-findings/file-review/selection-lines.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"selection-lines.d.ts","sourceRoot":"","sources":["../../../src/file-findings/file-review/selection-lines.ts"],"names":[],"mappings":"AAGA,mDAAmD;AACnD,MAAM,MAAM,SAAS,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAW/D;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI,CAavF;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,GAAG,IAAI,CAMnE"}
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import { sourceRangeOf } from "./source-marks.js";
|
|
2
|
+
import { tableRows } from "./table-cell.js";
|
|
2
3
|
// src/file-findings/file-review/selection-lines.ts
|
|
3
4
|
var SOURCE_BLOCK = "[data-source-start]";
|
|
5
|
+
/** Whether `range` covers some of `node`'s contents, not merely reaching its edge. */
|
|
6
|
+
function touches(range, node) {
|
|
7
|
+
const own = document.createRange();
|
|
8
|
+
own.selectNodeContents(node);
|
|
9
|
+
return range.compareBoundaryPoints(Range.END_TO_START, own) < 0 && range.compareBoundaryPoints(Range.START_TO_END, own) > 0;
|
|
10
|
+
}
|
|
4
11
|
/**
|
|
5
12
|
* The source lines of the rendered blocks (`Markdown sourceBlocks`) a
|
|
6
13
|
* selection in Preview touches, from the first block's start to the last
|
|
7
|
-
* block's end
|
|
8
|
-
* cover it. Null when it
|
|
14
|
+
* block's end; in a table, only the lines of the rows it touches. A selection
|
|
15
|
+
* that merely reaches the edge of a block does not cover it. Null when it
|
|
16
|
+
* touches no block.
|
|
9
17
|
*/
|
|
10
18
|
function previewSelectionLines(range, markdown) {
|
|
11
19
|
const covered = [];
|
|
12
20
|
for (const block of markdown.querySelectorAll(SOURCE_BLOCK)) {
|
|
13
|
-
if (block.parentElement?.closest(SOURCE_BLOCK)) continue;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
if (block.parentElement?.closest(SOURCE_BLOCK) || !touches(range, block)) continue;
|
|
22
|
+
const rows = tableRows(block).filter(({ row }) => touches(range, row));
|
|
23
|
+
if (rows.length > 0) covered.push(...rows.map(({ line }) => ({
|
|
24
|
+
startLine: line,
|
|
25
|
+
endLine: line
|
|
26
|
+
})));
|
|
27
|
+
else covered.push({
|
|
19
28
|
startLine: Number(block.dataset.sourceStart),
|
|
20
29
|
endLine: Number(block.dataset.sourceEnd)
|
|
21
30
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selection-lines.js","names":[],"sources":["../../../src/file-findings/file-review/selection-lines.ts"],"sourcesContent":["import { sourceRangeOf } from \"./source-marks\";\n\n/** An inclusive, 1-based range of source lines. */\nexport type LineRange = { startLine: number; endLine: number };\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\n\n/**\n * The source lines of the rendered blocks (`Markdown sourceBlocks`) a\n * selection in Preview touches, from the first block's start to the last\n * block's end. A selection that merely reaches the edge of a block does not
|
|
1
|
+
{"version":3,"file":"selection-lines.js","names":[],"sources":["../../../src/file-findings/file-review/selection-lines.ts"],"sourcesContent":["import { sourceRangeOf } from \"./source-marks\";\nimport { tableRows } from \"./table-cell\";\n\n/** An inclusive, 1-based range of source lines. */\nexport type LineRange = { startLine: number; endLine: number };\n\nconst SOURCE_BLOCK = \"[data-source-start]\";\n\n/** Whether `range` covers some of `node`'s contents, not merely reaching its edge. */\nfunction touches(range: Range, node: Node): boolean {\n const own = document.createRange();\n own.selectNodeContents(node);\n return range.compareBoundaryPoints(Range.END_TO_START, own) < 0 && range.compareBoundaryPoints(Range.START_TO_END, own) > 0;\n}\n\n/**\n * The source lines of the rendered blocks (`Markdown sourceBlocks`) a\n * selection in Preview touches, from the first block's start to the last\n * block's end; in a table, only the lines of the rows it touches. A selection\n * that merely reaches the edge of a block does not cover it. Null when it\n * touches no block.\n */\nexport function previewSelectionLines(range: Range, markdown: Element): LineRange | null {\n const covered: LineRange[] = [];\n for (const block of markdown.querySelectorAll<HTMLElement>(SOURCE_BLOCK)) {\n if (block.parentElement?.closest(SOURCE_BLOCK) || !touches(range, block)) continue;\n const rows = tableRows(block).filter(({ row }) => touches(range, row));\n if (rows.length > 0) covered.push(...rows.map(({ line }) => ({ startLine: line, endLine: line })));\n else covered.push({ startLine: Number(block.dataset.sourceStart), endLine: Number(block.dataset.sourceEnd) });\n }\n if (covered.length === 0) return null;\n return {\n startLine: Math.min(...covered.map((block) => block.startLine)),\n endLine: Math.max(...covered.map((block) => block.endLine)),\n };\n}\n\n/**\n * The source lines a selection in the Source listing covers. A selection that\n * ends at the very start of a later line does not include that line. Null when\n * either end is outside the lines' text.\n */\nexport function sourceSelectionLines(range: Range): LineRange | null {\n const covered = sourceRangeOf(range);\n if (!covered) return null;\n const { start, end } = covered;\n const endLine = end.column === 0 && end.line > start.line ? end.line - 1 : end.line;\n return { startLine: start.line, endLine };\n}\n"],"mappings":";;;AAMA,IAAM,eAAe;;AAGrB,SAAS,QAAQ,OAAc,MAAqB;CAClD,MAAM,MAAM,SAAS,YAAY;CACjC,IAAI,mBAAmB,IAAI;CAC3B,OAAO,MAAM,sBAAsB,MAAM,cAAc,GAAG,IAAI,KAAK,MAAM,sBAAsB,MAAM,cAAc,GAAG,IAAI;AAC5H;;;;;;;;AASA,SAAgB,sBAAsB,OAAc,UAAqC;CACvF,MAAM,UAAuB,CAAC;CAC9B,KAAK,MAAM,SAAS,SAAS,iBAA8B,YAAY,GAAG;EACxE,IAAI,MAAM,eAAe,QAAQ,YAAY,KAAK,CAAC,QAAQ,OAAO,KAAK,GAAG;EAC1E,MAAM,OAAO,UAAU,KAAK,CAAC,CAAC,QAAQ,EAAE,UAAU,QAAQ,OAAO,GAAG,CAAC;EACrE,IAAI,KAAK,SAAS,GAAG,QAAQ,KAAK,GAAG,KAAK,KAAK,EAAE,YAAY;GAAE,WAAW;GAAM,SAAS;EAAK,EAAE,CAAC;OAC5F,QAAQ,KAAK;GAAE,WAAW,OAAO,MAAM,QAAQ,WAAW;GAAG,SAAS,OAAO,MAAM,QAAQ,SAAS;EAAE,CAAC;CAC9G;CACA,IAAI,QAAQ,WAAW,GAAG,OAAO;CACjC,OAAO;EACL,WAAW,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,SAAS,CAAC;EAC9D,SAAS,KAAK,IAAI,GAAG,QAAQ,KAAK,UAAU,MAAM,OAA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