@viswa-test/test-citation 0.0.390 → 0.0.391
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/dist/cjs/features/CognitiveCompare/CitationAnchor.js +1 -1
- package/dist/cjs/features/CognitiveCompare/CitationAnchor.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/CitationRenderer.js +1 -1
- package/dist/cjs/features/CognitiveCompare/CitationRenderer.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/CognitiveCompare.js +1 -1
- package/dist/cjs/features/CognitiveCompare/CognitiveCompare.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/CognitiveCompareConstants.js +1 -1
- package/dist/cjs/features/CognitiveCompare/CognitiveCompareConstants.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/CognitiveComparehelpers.js +1 -1
- package/dist/cjs/features/CognitiveCompare/CognitiveComparehelpers.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/CognitivePopup.js +1 -1
- package/dist/cjs/features/CognitiveCompare/CognitivePopup.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/CompareContext.js +1 -1
- package/dist/cjs/features/CognitiveCompare/CompareContext.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/Guidelines/components/GuidelinePanel.js +1 -1
- package/dist/cjs/features/CognitiveCompare/Guidelines/components/GuidelinePanel.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/Guidelines/components/WebGptPanel.js +1 -1
- package/dist/cjs/features/CognitiveCompare/Guidelines/components/WebGptPanel.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js +1 -1
- package/dist/cjs/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/components/LHSSectionRow.js +1 -1
- package/dist/cjs/features/CognitiveCompare/components/LHSSectionRow.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/components/RHSSectionRow.js +1 -1
- package/dist/cjs/features/CognitiveCompare/components/RHSSectionRow.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/components/SectionAccordion.js +1 -1
- package/dist/cjs/features/CognitiveCompare/components/SectionAccordion.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/components/SubSectionAccordion.js +1 -1
- package/dist/cjs/features/CognitiveCompare/components/SubSectionAccordion.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/components/SvgConnectors.js +1 -1
- package/dist/cjs/features/CognitiveCompare/components/SvgConnectors.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/hooks/memoizedMarkdown.js +1 -1
- package/dist/cjs/features/CognitiveCompare/hooks/memoizedMarkdown.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/hooks/useCompareData.js +1 -1
- package/dist/cjs/features/CognitiveCompare/hooks/useCompareData.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/hooks/useLinesCalculator.js +1 -1
- package/dist/cjs/features/CognitiveCompare/hooks/useLinesCalculator.js.map +1 -1
- package/dist/cjs/features/CognitiveCompare/hooks/useSideBySide.js +1 -1
- package/dist/cjs/features/CognitiveCompare/hooks/useSideBySide.js.map +1 -1
- package/dist/cjs/features/PdfViewer/PdfToolbar.js +1 -1
- package/dist/cjs/features/PdfViewer/PdfToolbar.js.map +1 -1
- package/dist/cjs/features/PdfViewer/PdfViewer.css.js +1 -1
- package/dist/cjs/features/PdfViewer/PdfViewer.js +1 -1
- package/dist/cjs/features/PdfViewer/PdfViewer.js.map +1 -1
- package/dist/cjs/features/PdfViewer/rotationManager.js +1 -1
- package/dist/cjs/features/PdfViewer/rotationManager.js.map +1 -1
- package/dist/cjs/features/PdfViewer/usePdfHighlight.js +1 -1
- package/dist/cjs/features/PdfViewer/usePdfHighlight.js.map +1 -1
- package/dist/cjs/features/PdfViewer/zoomStateManager.js +2 -0
- package/dist/cjs/features/PdfViewer/zoomStateManager.js.map +1 -0
- package/dist/cjs/features/SegmentReviewComponents/CognitiveScoreBadge.js +1 -1
- package/dist/cjs/features/SegmentReviewComponents/CognitiveScoreBadge.js.map +1 -1
- package/dist/cjs/features/SegmentReviewComponents/reviewStepAdapters.js +1 -1
- package/dist/cjs/features/SegmentReviewComponents/reviewStepAdapters.js.map +1 -1
- package/dist/features/CognitiveCompare/CitationAnchor.js +1 -1
- package/dist/features/CognitiveCompare/CitationAnchor.js.map +1 -1
- package/dist/features/CognitiveCompare/CitationRenderer.js +1 -1
- package/dist/features/CognitiveCompare/CitationRenderer.js.map +1 -1
- package/dist/features/CognitiveCompare/CognitiveCompare.js +1 -1
- package/dist/features/CognitiveCompare/CognitiveCompare.js.map +1 -1
- package/dist/features/CognitiveCompare/CognitiveCompareConstants.js +1 -1
- package/dist/features/CognitiveCompare/CognitiveCompareConstants.js.map +1 -1
- package/dist/features/CognitiveCompare/CognitiveComparehelpers.js +1 -1
- package/dist/features/CognitiveCompare/CognitiveComparehelpers.js.map +1 -1
- package/dist/features/CognitiveCompare/CognitivePopup.js +1 -1
- package/dist/features/CognitiveCompare/CognitivePopup.js.map +1 -1
- package/dist/features/CognitiveCompare/CompareContext.js +1 -1
- package/dist/features/CognitiveCompare/CompareContext.js.map +1 -1
- package/dist/features/CognitiveCompare/Guidelines/components/GuidelinePanel.js +1 -1
- package/dist/features/CognitiveCompare/Guidelines/components/GuidelinePanel.js.map +1 -1
- package/dist/features/CognitiveCompare/Guidelines/components/WebGptPanel.js +1 -1
- package/dist/features/CognitiveCompare/Guidelines/components/WebGptPanel.js.map +1 -1
- package/dist/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js +1 -1
- package/dist/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.js.map +1 -1
- package/dist/features/CognitiveCompare/components/LHSSectionRow.js +1 -1
- package/dist/features/CognitiveCompare/components/LHSSectionRow.js.map +1 -1
- package/dist/features/CognitiveCompare/components/RHSSectionRow.js +1 -1
- package/dist/features/CognitiveCompare/components/RHSSectionRow.js.map +1 -1
- package/dist/features/CognitiveCompare/components/SectionAccordion.js +1 -1
- package/dist/features/CognitiveCompare/components/SectionAccordion.js.map +1 -1
- package/dist/features/CognitiveCompare/components/SubSectionAccordion.js +1 -1
- package/dist/features/CognitiveCompare/components/SubSectionAccordion.js.map +1 -1
- package/dist/features/CognitiveCompare/components/SvgConnectors.js +1 -1
- package/dist/features/CognitiveCompare/components/SvgConnectors.js.map +1 -1
- package/dist/features/CognitiveCompare/hooks/memoizedMarkdown.js +1 -1
- package/dist/features/CognitiveCompare/hooks/memoizedMarkdown.js.map +1 -1
- package/dist/features/CognitiveCompare/hooks/useCompareData.js +1 -1
- package/dist/features/CognitiveCompare/hooks/useCompareData.js.map +1 -1
- package/dist/features/CognitiveCompare/hooks/useLinesCalculator.js +1 -1
- package/dist/features/CognitiveCompare/hooks/useLinesCalculator.js.map +1 -1
- package/dist/features/CognitiveCompare/hooks/useSideBySide.js +1 -1
- package/dist/features/CognitiveCompare/hooks/useSideBySide.js.map +1 -1
- package/dist/features/PdfViewer/PdfToolbar.js +1 -1
- package/dist/features/PdfViewer/PdfToolbar.js.map +1 -1
- package/dist/features/PdfViewer/PdfViewer.css.js +1 -1
- package/dist/features/PdfViewer/PdfViewer.js +1 -1
- package/dist/features/PdfViewer/PdfViewer.js.map +1 -1
- package/dist/features/PdfViewer/rotationManager.js +1 -1
- package/dist/features/PdfViewer/rotationManager.js.map +1 -1
- package/dist/features/PdfViewer/usePdfHighlight.js +1 -1
- package/dist/features/PdfViewer/usePdfHighlight.js.map +1 -1
- package/dist/features/PdfViewer/zoomStateManager.js +2 -0
- package/dist/features/PdfViewer/zoomStateManager.js.map +1 -0
- package/dist/features/SegmentReviewComponents/CognitiveScoreBadge.js +1 -1
- package/dist/features/SegmentReviewComponents/CognitiveScoreBadge.js.map +1 -1
- package/dist/features/SegmentReviewComponents/reviewStepAdapters.js +1 -1
- package/dist/features/SegmentReviewComponents/reviewStepAdapters.js.map +1 -1
- package/dist/types/features/CognitiveCompare/CitationAnchor.d.ts +0 -2
- package/dist/types/features/CognitiveCompare/CitationAnchor.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/CitationRenderer.d.ts +1 -8
- package/dist/types/features/CognitiveCompare/CitationRenderer.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/CognitiveCompare.d.ts +1 -1
- package/dist/types/features/CognitiveCompare/CognitiveCompare.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/CognitiveCompareConstants.d.ts +1 -1
- package/dist/types/features/CognitiveCompare/CognitiveCompareConstants.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/CognitiveCompareTypes.d.ts +3 -12
- package/dist/types/features/CognitiveCompare/CognitiveCompareTypes.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/CognitiveComparehelpers.d.ts +0 -12
- package/dist/types/features/CognitiveCompare/CognitiveComparehelpers.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/CognitivePopup.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/CompareContext.d.ts +2 -9
- package/dist/types/features/CognitiveCompare/CompareContext.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/Guidelines/components/GuidelinePanel.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/Guidelines/components/WebGptPanel.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.d.ts +1 -14
- package/dist/types/features/CognitiveCompare/Guidelines/utils/processGuidelinesMarkdown.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/components/LHSSectionRow.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/components/RHSSectionRow.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/components/SectionAccordion.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/components/SubSectionAccordion.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/components/SvgConnectors.d.ts +3 -2
- package/dist/types/features/CognitiveCompare/components/SvgConnectors.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/hooks/memoizedMarkdown.d.ts +1 -2
- package/dist/types/features/CognitiveCompare/hooks/memoizedMarkdown.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/hooks/useCompareData.d.ts +1 -1
- package/dist/types/features/CognitiveCompare/hooks/useCompareData.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/hooks/useLinesCalculator.d.ts.map +1 -1
- package/dist/types/features/CognitiveCompare/hooks/useSideBySide.d.ts.map +1 -1
- package/dist/types/features/PdfViewer/PdfToolbar.d.ts.map +1 -1
- package/dist/types/features/PdfViewer/PdfViewer.d.ts.map +1 -1
- package/dist/types/features/PdfViewer/rotationManager.d.ts.map +1 -1
- package/dist/types/features/PdfViewer/usePdfHighlight.d.ts +1 -2
- package/dist/types/features/PdfViewer/usePdfHighlight.d.ts.map +1 -1
- package/dist/types/features/PdfViewer/zoomStateManager.d.ts +21 -0
- package/dist/types/features/PdfViewer/zoomStateManager.d.ts.map +1 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCompareData.js","sources":["../../../../../src/features/CognitiveCompare/hooks/useCompareData.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { getSideData, getRationale, hasValue, safeStringify, isMissingStr, DEVIATION_BADGE_SEPARATOR, resolveComparisonInputItems } from \"../CognitiveComparehelpers\";\nimport { ComparisonRow, SectionBlock, ProposedRuleData, RuleData, ComparisonConfig } from \"../CognitiveCompareTypes\";\nimport { buildComparisonRows } from \"../utils/buildComparisonRows\";\n\nconst DEFAULT_RULE_FALLBACK: RuleData = { id: \"\", title: \"\", similarity: 0, sections: [] };\n\nexport const useCognitiveTreeData = (\n treeData: Record<string, any> | undefined,\n maintainRelativeOrder: boolean,\n deviationData: Record<string, any> | null,\n resolvedComparisonConfig: ComparisonConfig,\n enableDeviationSchemaBackwardCompatibility: boolean = true,\n guidelinesData?: string | Record<string, any> | null,\n isGuidelineModeFromParent?: boolean,\n) => {\n // AdaptTreeData function \n // memoized to increase performance\n // Stabilize the deviationData reference by stringifying it.\n // This prevents React from triggering re-renders purely due to memory reference changes.\n // We keep accepting it as a string so the memo dep stays content-based.\n const deviationDataStr = typeof deviationData === \"string\" ? deviationData : JSON.stringify(deviationData || {});\n\n // ── NEW: Check for either the new learnings_data or the old artifactData ──\n const isGuidelineMode = isGuidelineModeFromParent ?? Boolean(\n typeof guidelinesData === \"string\"\n ? guidelinesData.trim()\n : guidelinesData &&\n (guidelinesData.learnings_data ||\n guidelinesData.data?.artifactData?.userStorySnapshot),\n );\n\n const { activeProposed, activeVariants, comparisonRows, parseError } = useMemo(() => {\n if (!treeData || Object.keys(treeData).length === 0) {\n return {\n activeProposed: {} as ProposedRuleData,\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: \"Tree data is required\",\n };\n }\n const stableDeviationData = JSON.parse(deviationDataStr);\n\n try {\n const nodes = treeData.nodes || treeData;\n let baseSections: any[] = []; \n let refSections: any[] = []; \n let comparisonRows: ComparisonRow[] = [];\n\n const rootId = treeData.base_root_id;\n const indexMap = treeData.input_index_map || { \"0\": \"left\", \"1\": \"right\" };\n const rootNode = treeData[rootId] || nodes[rootId];\n\n if (!rootNode || rootNode.display_node === false) {\n return {\n activeProposed: { title: \"No Data\", sections: [] },\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: null,\n };\n }\n \n const contentMapping = treeData.content_mapping || {};\n const getNode = (nodeId: string) => treeData[nodeId] || nodes[nodeId];\n \n\n const normalizeEvaluationResult = (rawEvaluationResult: any, nodeLeftId: string, nodeRightId: string) => {\n if (!rawEvaluationResult || typeof rawEvaluationResult !== \"object\") {\n return rawEvaluationResult || null;\n }\n\n // Old format already supported by UI.\n if (rawEvaluationResult.deviations) {\n return rawEvaluationResult;\n }\n\n if (enableDeviationSchemaBackwardCompatibility) {\n return rawEvaluationResult;\n }\n\n const numericDeviationKeys = Object.keys(rawEvaluationResult).filter(\n (k) => /^\\d+$/.test(k),\n );\n\n if (!numericDeviationKeys.length) {\n return rawEvaluationResult;\n }\n\n const sortedDeviationKeys = numericDeviationKeys.sort(\n (a, b) => Number(a) - Number(b),\n );\n const normalizedDeviations: Record<string, any> = {};\n const deviationEntries: Record<string, any> = {};\n let firstEntry: any = null;\n\n sortedDeviationKeys.forEach((devKey) => {\n const entry = rawEvaluationResult[devKey];\n if (!entry || typeof entry !== \"object\") return;\n if (!firstEntry) firstEntry = entry;\n\n const isSameEvaluation =\n safeStringify(entry?.evaluation_outputs?.output_value)\n .trim()\n .toLowerCase() === \"same\";\n const shouldShowHighlights =\n (!entry?.status || entry.status === \"pending\") && !isSameEvaluation;\n const deviationHighlight =\n entry?.deviation_highlight ||\n entry?.web_search_answer?.deviation_highlight;\n\n const citationHighlights = (docId: string): string[] => {\n const citations = entry?.cognitive_decisioning?.citations || entry?.citations || {};\n return Object.values(citations)\n .map((citation: any) => citation?.[docId]?.highlighted_text)\n .filter((text: any) => typeof text === \"string\" && text.trim().length > 0);\n };\n\n const firstNonEmpty = (...values: any[]): string[] => {\n for (const value of values) {\n if (Array.isArray(value) && value.some((text) => !isMissingStr(text))) {\n return value;\n }\n }\n return [];\n };\n\n const leftHighlights: string[] = shouldShowHighlights\n ? firstNonEmpty(\n entry?.deviation_highlights?.[nodeLeftId] ||\n entry?.deviation_highlights?.[indexMap[\"0\"] as string],\n typeof deviationHighlight === \"string\"\n ? [deviationHighlight]\n : [],\n citationHighlights(nodeLeftId),\n citationHighlights(indexMap[\"0\"] as string),\n )\n : [];\n\n const rightHighlights: string[] = shouldShowHighlights\n ? firstNonEmpty(\n entry?.deviation_highlights?.[nodeRightId] ||\n entry?.deviation_highlights?.[indexMap[\"1\"] as string],\n citationHighlights(nodeRightId),\n citationHighlights(indexMap[\"1\"] as string),\n )\n : [];\n\n normalizedDeviations[devKey] = {\n [indexMap[\"0\"] as string]: leftHighlights[0] || \"\", \n [indexMap[\"1\"] as string]: rightHighlights[0] || \"\",\n deviation_summary: entry?.deviation_summary || \"\",\n deviation_title: entry?.deviation_title,\n deviation_impact: entry?.deviation_impact,\n deviation_explanation: entry?.deviation_explanation,\n evaluation_outputs: entry?.evaluation_outputs,\n cognitive_decisioning: entry?.cognitive_decisioning,\n deviation_highlights: entry?.deviation_highlights,\n };\n\n deviationEntries[devKey] = entry;\n });\n\n return {\n ...rawEvaluationResult,\n deviation_title: firstEntry?.deviation_title || rawEvaluationResult?.deviation_title,\n deviation_impact: firstEntry?.deviation_impact || rawEvaluationResult?.deviation_impact,\n deviation_summary: firstEntry?.deviation_summary || rawEvaluationResult?.deviation_summary,\n deviation_explanation:\n firstEntry?.deviation_explanation || rawEvaluationResult?.deviation_explanation,\n evaluation_outputs:\n firstEntry?.evaluation_outputs || rawEvaluationResult?.evaluation_outputs,\n cognitive_decisioning:\n firstEntry?.cognitive_decisioning || rawEvaluationResult?.cognitive_decisioning,\n deviations: normalizedDeviations,\n deviation_entries: deviationEntries,\n };\n };\n\n // UNIVERSAL RE-ROUTING ENGINE (WITH SORTING FIX)\n const reRouteRHSTree = (sections: any[]) => {\n const allNodesMap = new Map<string, any>();\n \n const indexNodes = (nodes: any[]) => {\n nodes.forEach(node => {\n if (node.id) allNodesMap.set(node.id, node);\n if (node.subsections?.length) indexNodes(node.subsections);\n });\n };\n indexNodes(sections);\n \n const moveNodes = (nodes: any[], parentNode?: any): any[] => {\n let filteredNodes: any[] = [];\n \n for (const node of nodes) {\n const targetParentId = node.ref_parent_section_node_id;\n \n if (targetParentId && allNodesMap.has(targetParentId) && targetParentId !== parentNode?.id) {\n const targetParent = allNodesMap.get(targetParentId)!;\n if (!targetParent.subsections) targetParent.subsections = [];\n \n if (!targetParent.subsections.some((s: any) => s.id === node.id)) {\n targetParent.subsections.push(node);\n }\n } else {\n if (node.subsections?.length) {\n node.subsections = moveNodes(node.subsections, node);\n }\n filteredNodes.push(node);\n }\n }\n return filteredNodes;\n };\n \n const finalSections = moveNodes(sections);\n\n // Sort step added to ensure display_index is respected after re-routing\n const sortSubsections = (nodes: any[]) => {\n nodes.forEach(node => {\n if (node.subsections && node.subsections.length > 0) {\n node.subsections.sort((a: any, b: any) => {\n if (a.selfIndex < 0 && b.selfIndex >= 0) return 1;\n if (a.selfIndex >= 0 && b.selfIndex < 0) return -1;\n return (a.selfIndex || 0) - (b.selfIndex || 0);\n });\n sortSubsections(node.subsections);\n }\n });\n };\n\n sortSubsections(finalSections);\n return finalSections;\n };\n\n const getNodeInputIds = (node: any) => {\n const nodeInputKeys = node.comparison_inputs ? Object.keys(node.comparison_inputs) : [];\n let nodeLeftId = indexMap[\"0\"];\n let nodeRightId = indexMap[\"1\"];\n\n if (nodeInputKeys.length > 0) {\n nodeLeftId = nodeInputKeys.includes(indexMap[\"0\"]) ? indexMap[\"0\"] : nodeInputKeys[0];\n nodeRightId = nodeInputKeys.includes(indexMap[\"1\"]) ? indexMap[\"1\"] : (nodeInputKeys.length > 1 ? nodeInputKeys[1] : nodeInputKeys[0]);\n }\n\n return { nodeLeftId, nodeRightId };\n };\n\n const getParentContentId = (attrs: any) =>\n attrs?.entity_id ||\n attrs?.ref_parent_section_node_id ||\n attrs?.parent_entity_id ||\n null;\n\n const makeSectionBlock = (\n nodeId: string,\n item: any,\n evaluationResult: any,\n rationale: any,\n ): SectionBlock => {\n const attrs = item.attributes || {};\n const data = item.data || {};\n const displayTitle = attrs.display_title !== false;\n const displayContent = attrs.display_content !== false;\n const title = displayTitle ? safeStringify(data.title || \"\") : \"\";\n const content = displayContent ? safeStringify(data.content || \"\") : \"\";\n const changeHistory = displayContent ? safeStringify(data.change_history || \"\") : \"\";\n const selfIndex =\n attrs.display_index !== undefined && attrs.display_index !== null\n ? Number(attrs.display_index)\n : -1;\n const parentContentId = getParentContentId(attrs);\n const hasData = !!(title.trim() || content.trim());\n\n return {\n id: `${nodeId}::${item.contentId}`,\n nodeId,\n contentId: item.contentId,\n parentContentId,\n title,\n content,\n change_history: changeHistory,\n displayTitle,\n displayContent,\n subsections: [],\n ...(hasData ? rationale : { score: undefined, relation: \"not_defined\" }),\n evaluationResult,\n evaluationResults: evaluationResult ? [evaluationResult] : [],\n selfIndex,\n refIndexes: [],\n refContentIds: [],\n ref_parent_section_node_id: parentContentId,\n } as SectionBlock;\n };\n\n const mergeBlock = (target: any, incoming: any) => {\n target.refIndexes = Array.from(new Set([...(target.refIndexes || []), ...(incoming.refIndexes || [])]));\n target.refContentIds = Array.from(new Set([...(target.refContentIds || []), ...(incoming.refContentIds || [])]));\n\n const existingChildKeys = new Set(\n (target.subsections || []).map((child: any) =>\n child.id || child.contentId || child.nodeId,\n ),\n );\n (incoming.subsections || []).forEach((child: any) => {\n const childKey = child.id || child.contentId || child.nodeId;\n if (!existingChildKeys.has(childKey)) {\n target.subsections = [...(target.subsections || []), child];\n existingChildKeys.add(childKey);\n }\n });\n\n const mergedEvaluationResults = [\n ...(target.evaluationResults || (target.evaluationResult ? [target.evaluationResult] : [])),\n ...(incoming.evaluationResults || (incoming.evaluationResult ? [incoming.evaluationResult] : [])),\n ].filter(Boolean);\n const seenEvaluationResults = new Set<string>();\n target.evaluationResults = mergedEvaluationResults.filter((result: any) => {\n const key = result?.nodeId || JSON.stringify(Object.keys(result?.deviations || result || {}));\n if (seenEvaluationResults.has(key)) return false;\n seenEvaluationResults.add(key);\n return true;\n });\n\n if (!target.evaluationResult && incoming.evaluationResult) target.evaluationResult = incoming.evaluationResult;\n if (!target.cognitiveData && incoming.cognitiveData) target.cognitiveData = incoming.cognitiveData;\n\n return target;\n };\n\n const sortFn = (a: any, b: any) => {\n if (a.selfIndex! < 0 && b.selfIndex! >= 0) return 1;\n if (a.selfIndex! >= 0 && b.selfIndex! < 0) return -1;\n return a.selfIndex! - b.selfIndex!;\n };\n\n const buildSideSections = (nodeId: string, sideIndex: \"0\" | \"1\"): SectionBlock[] => {\n const node = getNode(nodeId);\n if (!node || node.display_node === false) return [];\n \n if (isGuidelineMode && sideIndex === \"1\") return [];\n\n const { nodeLeftId, nodeRightId } = getNodeInputIds(node);\n const rationale = getRationale(node);\n const rawEvaluationResult =\n stableDeviationData?.[nodeId]?.evaluation_result || node.evaluation_result || null;\n const normalizedEvaluationResult = normalizeEvaluationResult(rawEvaluationResult, nodeLeftId, nodeRightId);\n const evaluationResult = normalizedEvaluationResult && typeof normalizedEvaluationResult === \"object\"\n ? { ...normalizedEvaluationResult, nodeId }\n : normalizedEvaluationResult;\n const items = resolveComparisonInputItems(node, sideIndex, indexMap, contentMapping);\n\n const sections = items.map((item) =>\n makeSectionBlock(nodeId, item, evaluationResult, rationale),\n );\n\n if (node.next) {\n const childSections = (Object.values(node.next) as string[]).flatMap((childId) =>\n buildSideSections(childId, sideIndex),\n );\n sections.forEach((section) => {\n const matchedChildren = childSections.filter((child: any) =>\n !child.parentContentId ||\n child.parentContentId === section.contentId ||\n child.parentContentId === section.parentContentId,\n );\n section.subsections = matchedChildren.length ? matchedChildren : childSections;\n });\n }\n\n return sections;\n };\n\n if (!maintainRelativeOrder) {\n if (rootNode.next) {\n (Object.values(rootNode.next) as string[]).forEach((nodeId) => {\n const node = getNode(nodeId);\n if (!node || node.display_node === false) return;\n\n const leftBlocks = buildSideSections(nodeId, \"0\");\n\n if (isGuidelineMode) {\n baseSections.push(...leftBlocks);\n return;\n }\n\n const rightBlocks = reRouteRHSTree(buildSideSections(nodeId, \"1\"));\n comparisonRows.push(\n ...buildComparisonRows(nodeId, leftBlocks, rightBlocks),\n );\n });\n }\n\n if (!isGuidelineMode) {\n baseSections = comparisonRows.map((row) => row.left);\n refSections = comparisonRows.map((row) => row.right);\n }\n\n } else {\n const buildRelativeOrderMapping = (nodeMap?: Record<string, string> | null, depth = 0) => {\n let refSections: SectionBlock[] = [];\n let baseSections: SectionBlock[] = [];\n if (!nodeMap) return { refSections, baseSections };\n \n const rightNodesHash: Record<string, SectionBlock> = {};\n const leftNodesHash: Record<string, SectionBlock> = {};\n let rightNodeOrphanIdx = -1;\n let leftNodeOrphanIdx = -1;\n\n for (const nodeIdx in nodeMap) {\n const nodeId = nodeMap[nodeIdx];\n const node = getNode(nodeId);\n if (!node || node.display_node === false) continue;\n\n const { nodeLeftId, nodeRightId } = getNodeInputIds(node);\n const rationale = getRationale(node);\n const rawEvaluationResult = stableDeviationData?.[nodeId]?.evaluation_result || node.evaluation_result || null;\n const normalizedEvaluationResult = normalizeEvaluationResult(rawEvaluationResult, nodeLeftId, nodeRightId);\n const evaluationResult = normalizedEvaluationResult && typeof normalizedEvaluationResult === \"object\"\n ? { ...normalizedEvaluationResult, nodeId }\n : normalizedEvaluationResult;\n\n const { refSections: refSubSections, baseSections: baseSubSections } = buildRelativeOrderMapping(node.next, depth + 1);\n\n const leftItems = resolveComparisonInputItems(node, \"0\", indexMap, contentMapping);\n const leftBlocks = leftItems.map((item) => {\n const block = makeSectionBlock(nodeId, item, evaluationResult, rationale);\n if (block.selfIndex === -1) block.selfIndex = leftNodeOrphanIdx--;\n return block;\n });\n\n let rightBlocks: any[] = [];\n if (!isGuidelineMode) {\n const rightItems = resolveComparisonInputItems(node, \"1\", indexMap, contentMapping);\n rightBlocks = rightItems.map((item) => {\n const block = makeSectionBlock(nodeId, item, evaluationResult, rationale);\n if (block.selfIndex === -1) block.selfIndex = rightNodeOrphanIdx--;\n return block;\n });\n }\n\n leftBlocks.forEach((leftBlock: any) => {\n rightBlocks.forEach((rightBlock: any) => {\n if (Number(rightBlock.selfIndex) >= 0 && Number(leftBlock.selfIndex) >= 0) {\n if (!rightBlock.refIndexes?.includes(Number(leftBlock.selfIndex))) rightBlock.refIndexes?.push(Number(leftBlock.selfIndex));\n if (!leftBlock.refIndexes?.includes(Number(rightBlock.selfIndex))) leftBlock.refIndexes?.push(Number(rightBlock.selfIndex));\n }\n if (leftBlock.contentId && !rightBlock.refContentIds?.includes(leftBlock.contentId)) rightBlock.refContentIds?.push(leftBlock.contentId);\n if (rightBlock.contentId && !leftBlock.refContentIds?.includes(rightBlock.contentId)) leftBlock.refContentIds?.push(rightBlock.contentId);\n });\n });\n\n rightBlocks.forEach((rightBlock: any) => {\n const matchedSubSections = refSubSections.filter((sub: any) =>\n !sub.parentContentId ||\n sub.parentContentId === rightBlock.contentId ||\n sub.parentContentId === rightBlock.parentContentId ||\n rightBlock.refContentIds?.includes(sub.parentContentId),\n );\n if (matchedSubSections.length > 0) rightBlock.subsections = matchedSubSections;\n\n const rightHashKey = depth === 0\n ? String(rightBlock.selfIndex)\n : `${rightBlock.selfIndex}_${rightBlock.contentId || nodeId}`;\n rightNodesHash[rightHashKey] = rightNodesHash[rightHashKey]\n ? mergeBlock(rightNodesHash[rightHashKey], rightBlock)\n : rightBlock;\n });\n\n leftBlocks.forEach((leftBlock: any) => {\n const matchedSubSections = baseSubSections.filter((sub: any) =>\n !sub.parentContentId ||\n sub.parentContentId === leftBlock.contentId ||\n sub.parentContentId === leftBlock.parentContentId ||\n leftBlock.refContentIds?.includes(sub.parentContentId),\n );\n if (matchedSubSections.length > 0) leftBlock.subsections = matchedSubSections;\n\n const leftHashKey = depth === 0\n ? String(leftBlock.selfIndex)\n : `${leftBlock.selfIndex}_${leftBlock.contentId || nodeId}`;\n leftNodesHash[leftHashKey] = leftNodesHash[leftHashKey]\n ? mergeBlock(leftNodesHash[leftHashKey], leftBlock)\n : leftBlock;\n });\n }\n\n refSections = Object.values(rightNodesHash);\n baseSections = Object.values(leftNodesHash);\n\n refSections.sort(sortFn);\n baseSections.sort(sortFn);\n\n return { refSections, baseSections };\n };\n\n const { refSections: righSections, baseSections: leftSections } = buildRelativeOrderMapping(rootNode.next);\n \n if (!isGuidelineMode) {\n refSections = reRouteRHSTree(righSections);\n }\n baseSections = leftSections;\n }\n\n const rootLeftData = getSideData(rootNode, \"0\", indexMap, contentMapping);\n const rootRightData = getSideData(rootNode, \"1\", indexMap, contentMapping);\n\n const activeProposed: ProposedRuleData = {\n title: rootLeftData.title || \"Uploaded Contract\",\n description: rootNode.decision_scope_description || \"\",\n sections: baseSections,\n };\n\n // ── NEW: Extract the title dynamically based on the new learnings_data structure ──\n const getGuidelineTitle = () => {\n if (\n typeof guidelinesData !== \"string\" &&\n guidelinesData?.learnings_data &&\n Object.keys(guidelinesData.learnings_data).length > 0\n ) {\n const firstKey = Object.keys(guidelinesData.learnings_data)[0];\n return guidelinesData.learnings_data[firstKey]?.title || \"Rulebook Guidelines\";\n }\n return (\n (typeof guidelinesData !== \"string\" &&\n guidelinesData?.data?.artifactTitle) ||\n \"Rulebook Guidelines\"\n );\n };\n\n const activeVariant: RuleData = {\n id: \"tree-variant-1\",\n title: isGuidelineMode ? getGuidelineTitle() : (rootRightData.title || \"Reference Template\"),\n similarity: 0,\n sections: refSections,\n analysis: { rule_difference_comparison: { summary: { overall_score: 0, overall_summary: rootNode.decision_scope_description || \"\" }, fields: {} } },\n };\n\n return {\n activeProposed,\n activeVariants: [activeVariant],\n comparisonRows,\n parseError: null,\n };\n } catch (err: unknown) {\n console.error(\"Data Transformation Error: \", err);\n return {\n activeProposed: {} as ProposedRuleData,\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: err instanceof Error ? err.message : \"Unknown Parsing Error\",\n };\n }\n }, [\n treeData,\n maintainRelativeOrder,\n deviationDataStr,\n enableDeviationSchemaBackwardCompatibility,\n guidelinesData,\n isGuidelineMode,\n ]);\n\n // 2. Extracted section references\n const existingRule = activeVariants?.[0] || DEFAULT_RULE_FALLBACK;\n \n const proposedSections = useMemo(\n () => (activeProposed?.sections || []) as SectionBlock[],\n [activeProposed?.sections]\n );\n \n const existingSections = useMemo(\n () => (existingRule.sections || []) as SectionBlock[],\n [existingRule.sections]\n );\n\n const hasSectionAccordions =\n proposedSections.length > 0 || existingSections.length > 0;\n\n const visibleFields = useMemo(() => {\n return resolvedComparisonConfig.fields.filter(({ key }) => {\n if (hasSectionAccordions && key === \"description\") return false;\n return hasValue(activeProposed?.[key as keyof ProposedRuleData]) || hasValue(existingRule[key as keyof RuleData]);\n });\n }, [activeProposed, existingRule, hasSectionAccordions, resolvedComparisonConfig.fields]);\n\n // @ts-ignore\n const { parentDeviationRecord, registry: deviationNumberRegistry, deviationParentRegistry } = useMemo(() => {\n const parentDeviationRecord: Record<string, SectionBlock[]> = {};\n const registry: Record<string, { index: number; rootKey: string; parentNum: number }> = {};\n const counters: Record<string, number> = {};\n // Add a fallback id counter to ensure no deviations are left without ID even when backend does not provide any id.\n let fallbackIdCounter = 0;\n const leftDocId = treeData?.input_index_map?.[\"0\"];\n const rightDocId = treeData?.input_index_map?.[\"1\"];\n\n const resolveRootKeyAndParentNum = (\n rootSec: SectionBlock,\n side: \"left\" | \"right\",\n ): { rootKey: string; parentNum: number } => {\n if (!maintainRelativeOrder) {\n const idx = side === \"left\"\n ? proposedSections.indexOf(rootSec)\n : existingSections.indexOf(rootSec);\n return { rootKey: `${side}:${idx}`, parentNum: idx + 1 };\n }\n\n if (side === \"left\") {\n const selfIdx = (rootSec as any).selfIndex;\n const parentNum = selfIdx !== undefined && selfIdx >= 0 \n ? selfIdx + 1 \n : proposedSections.indexOf(rootSec) + 1;\n return { rootKey: `left-root:${rootSec.id}`, parentNum };\n }\n\n const rhsSelfIndex = (rootSec as any).selfIndex;\n const mappedLhs = proposedSections.find(\n (l: any) => l.refIndexes?.includes(rhsSelfIndex),\n );\n\n if (mappedLhs) {\n const lhsSelfIdx = (mappedLhs as any).selfIndex;\n const parentNum = lhsSelfIdx !== undefined && lhsSelfIdx >= 0 \n ? lhsSelfIdx + 1 \n : proposedSections.indexOf(mappedLhs) + 1;\n return { rootKey: `left-root:${mappedLhs.id}`, parentNum };\n }\n\n // True RHS orphan\n const parentNum = rhsSelfIndex !== undefined && rhsSelfIndex >= 0 \n ? rhsSelfIndex + 1 \n : existingSections.indexOf(rootSec) + 1;\n return { rootKey: `right-orphan-root:${rootSec.id}`, parentNum };\n };\n\n const processDeviations = (evalNode: any, rootKey: string, parentNum: number) => {\n const evaluationResults = evalNode?.evaluationResults?.length\n ? evalNode.evaluationResults\n : (evalNode?.evaluationResult ? [evalNode.evaluationResult] : []);\n\n evaluationResults.forEach((evaluationResult: any) => {\n const deviations = evaluationResult?.deviations || {};\n\n Object.keys(deviations).sort().forEach(devKey => {\n const devMap = deviations[devKey];\n if (!devMap) return;\n\n // changed the code because this logic was too strict and missed\n // cases where highlights were present in normalized/citation-backed data.\n const hasLeftHighlight = !isMissingStr(devMap[leftDocId as string]);\n const hasRightHighlight = !isMissingStr(devMap[rightDocId as string]);\n if (hasLeftHighlight || hasRightHighlight) {\n const registryNodeId = evaluationResult?.nodeId || evalNode.nodeId || evalNode.id;\n const refId = `${registryNodeId}${DEVIATION_BADGE_SEPARATOR}${devKey}`;\n if (registry[refId] === undefined) {\n if (counters[rootKey] === undefined) counters[rootKey] = 1;\n registry[refId] = { index: counters[rootKey]++, rootKey, parentNum };\n }\n }\n });\n });\n };\n\n // Resolve the correct child node at each level using id/refIndexes matching\n // rather than blind array-position (`subsections[i]`), so cross-routed\n // subsections are attributed to their actual structural parent.\n const findMatchingChild = (\n children: SectionBlock[] | undefined,\n target: SectionBlock | undefined,\n ): SectionBlock | undefined => {\n if (!children || !target) return undefined;\n return children.find((c: any) =>\n c.id === target.id ||\n (c.nodeId && c.nodeId === (target as any).nodeId) ||\n (c.contentId && c.contentId === (target as any).contentId)\n ) || undefined;\n };\n\n const traverse = (\n leftNode: SectionBlock | undefined | null,\n evalNode: SectionBlock | undefined | null,\n rightNode: SectionBlock | undefined | null,\n rootKey: string,\n parentNum: number,\n isRoot: boolean,\n parentNode: SectionBlock,\n ) => {\n if (evalNode) {\n processDeviations(evalNode, rootKey, parentNum);\n }\n\n if (evalNode && !isRoot) {\n const safeParentId = parentNode?.id || `fallback_parent_${fallbackIdCounter++}`;\n if (!parentDeviationRecord[safeParentId]) {\n parentDeviationRecord[safeParentId] = [];\n }\n parentDeviationRecord[safeParentId].push(evalNode);\n }\n\n const subs = evalNode?.subsections || leftNode?.subsections || rightNode?.subsections || [];\n subs.forEach((childEvalNode: any) => {\n const matchedLeft = findMatchingChild(leftNode?.subsections, childEvalNode);\n const matchedRight = findMatchingChild(rightNode?.subsections, childEvalNode);\n traverse(\n childEvalNode,\n matchedLeft,\n matchedRight,\n rootKey,\n parentNum,\n false,\n evalNode || parentNode,\n );\n });\n };\n\n proposedSections.forEach((rootSec) => {\n const { rootKey, parentNum } = resolveRootKeyAndParentNum(rootSec, \"left\");\n let rightSec = null;\n if (maintainRelativeOrder) {\n const rhsSelfIndex = (rootSec as any).refIndexes?.[0];\n rightSec = existingSections.find(s => (s as any).selfIndex === rhsSelfIndex);\n } else {\n rightSec = existingSections[proposedSections.indexOf(rootSec)];\n }\n traverse(rootSec, rootSec, rightSec, rootKey, parentNum, true, rootSec);\n });\n\n if (!isGuidelineMode) {\n existingSections.forEach((rootSec) => {\n const { rootKey, parentNum } = resolveRootKeyAndParentNum(rootSec, \"right\");\n const isOrphan = rootKey.startsWith(\"right-orphan-root:\");\n\n if (isOrphan) {\n traverse(rootSec, null, rootSec, rootKey, parentNum, true, rootSec);\n }\n });\n }\n\n const deviationNumberRegistry = Object.fromEntries(\n Object.entries(registry).map(([k, v]) => [k, v.index])\n );\n const deviationParentRegistry = Object.fromEntries(\n Object.entries(registry).map(([k, v]) => [k, v.parentNum])\n );\n\n return { parentDeviationRecord, registry: deviationNumberRegistry, deviationParentRegistry };\n\n }, [proposedSections, existingSections, maintainRelativeOrder, treeData, isGuidelineMode]);\n\n return {\n isGuidelineMode, // ── NEW ──\n activeProposed,\n activeVariants,\n comparisonRows,\n existingRule,\n proposedSections,\n existingSections,\n visibleFields,\n parentDeviationRecord,\n deviationNumberRegistry,\n deviationParentRegistry,\n parseError\n };\n};\n"],"names":["DEFAULT_RULE_FALLBACK","id","title","similarity","sections","treeData","maintainRelativeOrder","deviationData","resolvedComparisonConfig","enableDeviationSchemaBackwardCompatibility","guidelinesData","isGuidelineModeFromParent","deviationDataStr","JSON","stringify","isGuidelineMode","Boolean","trim","learnings_data","data","artifactData","userStorySnapshot","activeProposed","activeVariants","comparisonRows","parseError","useMemo","Object","keys","length","stableDeviationData","parse","nodes","baseSections","refSections","rootId","base_root_id","indexMap","input_index_map","rootNode","display_node","contentMapping","content_mapping","getNode","nodeId","normalizeEvaluationResult","rawEvaluationResult","nodeLeftId","nodeRightId","deviations","numericDeviationKeys","filter","k","test","sortedDeviationKeys","sort","a","b","Number","normalizedDeviations","deviationEntries","firstEntry","forEach","devKey","entry","isSameEvaluation","safeStringify","evaluation_outputs","output_value","toLowerCase","shouldShowHighlights","status","deviationHighlight","deviation_highlight","web_search_answer","citationHighlights","docId","citations","cognitive_decisioning","values","map","citation","highlighted_text","text","firstNonEmpty","value","Array","isArray","some","isMissingStr","leftHighlights","deviation_highlights","rightHighlights","deviation_summary","deviation_title","deviation_impact","deviation_explanation","deviation_entries","reRouteRHSTree","allNodesMap","Map","indexNodes","node","set","subsections","moveNodes","parentNode","filteredNodes","targetParentId","ref_parent_section_node_id","has","targetParent","get","s","push","finalSections","sortSubsections","selfIndex","getNodeInputIds","nodeInputKeys","comparison_inputs","includes","getParentContentId","attrs","entity_id","parent_entity_id","makeSectionBlock","item","evaluationResult","rationale","attributes","displayTitle","display_title","displayContent","display_content","content","changeHistory","change_history","display_index","parentContentId","hasData","contentId","score","relation","evaluationResults","refIndexes","refContentIds","mergeBlock","target","incoming","from","Set","existingChildKeys","child","childKey","add","mergedEvaluationResults","seenEvaluationResults","result","key","cognitiveData","sortFn","buildSideSections","sideIndex","getRationale","evaluation_result","normalizedEvaluationResult","resolveComparisonInputItems","next","childSections","flatMap","childId","section","matchedChildren","buildRelativeOrderMapping","nodeMap","depth","rightNodesHash","leftNodesHash","rightNodeOrphanIdx","leftNodeOrphanIdx","nodeIdx","refSubSections","baseSubSections","leftBlocks","block","rightBlocks","rightItems","leftBlock","rightBlock","matchedSubSections","sub","rightHashKey","String","leftHashKey","righSections","leftSections","buildComparisonRows","row","left","right","rootLeftData","getSideData","rootRightData","description","decision_scope_description","firstKey","artifactTitle","getGuidelineTitle","analysis","rule_difference_comparison","summary","overall_score","overall_summary","fields","err","console","error","Error","message","existingRule","proposedSections","existingSections","hasSectionAccordions","visibleFields","hasValue","parentDeviationRecord","registry","deviationNumberRegistry","deviationParentRegistry","counters","fallbackIdCounter","leftDocId","rightDocId","resolveRootKeyAndParentNum","rootSec","side","idx","indexOf","rootKey","parentNum","selfIdx","rhsSelfIndex","mappedLhs","find","l","lhsSelfIdx","findMatchingChild","children","c","traverse","leftNode","evalNode","rightNode","isRoot","devMap","hasLeftHighlight","hasRightHighlight","refId","DEVIATION_BADGE_SEPARATOR","index","processDeviations","safeParentId","childEvalNode","matchedLeft","matchedRight","rightSec","startsWith","fromEntries","entries","v"],"mappings":"mLAKA,MAAMA,EAAkC,CAAEC,GAAI,GAAIC,MAAO,GAAIC,WAAY,EAAGC,SAAU,iCAElD,CAClCC,EACAC,EACAC,EACAC,EACAC,GAAsD,EACtDC,EACAC,KAOM,MAAAC,EAA4C,iBAAlBL,EAA6BA,EAAgBM,KAAKC,UAAUP,GAAiB,CAAA,GAGvGQ,EAAkBJ,GAA6BK,QACzB,iBAAnBN,EACHA,EAAeO,OACfP,IACCA,EAAeQ,gBACdR,EAAeS,MAAMC,cAAcC,qBAGrCC,eAAEA,EAAgBC,eAAAA,EAAAC,eAAgBA,aAAgBC,GAAeC,EAAAA,QAAQ,KAC7E,IAAKrB,GAA6C,IAAjCsB,OAAOC,KAAKvB,GAAUwB,OAC9B,MAAA,CACLP,eAAgB,CAAC,EACjBC,eAAgB,GAChBC,eAAgB,GAChBC,WAAY,yBAGV,MAAAK,EAAsBjB,KAAKkB,MAAMnB,GAEnC,IACI,MAAAoB,EAAQ3B,EAAS2B,OAAS3B,EAChC,IAAI4B,EAAsB,GACtBC,EAAqB,GACrBV,EAAkC,GAEtC,MAAMW,EAAS9B,EAAS+B,aAClBC,EAAWhC,EAASiC,iBAAmB,CAAE,EAAK,OAAQ,EAAK,SAC3DC,EAAWlC,EAAS8B,IAAWH,EAAMG,GAE3C,IAAKI,IAAsC,IAA1BA,EAASC,aACjB,MAAA,CACLlB,eAAgB,CAAEpB,MAAO,UAAWE,SAAU,IAC9CmB,eAA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AAI+B,EAAW,KACf,GAAIpQ,EAAuB,CACnB,MAAA4O,EAAgBP,EAAgB1F,aAAa,GACnDyH,EAAW5C,EAAiBsB,KAAWnI,GAAAA,EAAUI,YAAc6H,EAAY,MAE3EwB,EAAW5C,EAAiBD,EAAiBiB,QAAQH,IAEvDe,EAASf,EAASA,EAAS+B,EAAU3B,EAASC,GAAW,EAAML,KAG5D5N,GACc+M,EAAAhK,QAAS6K,IACxB,MAAMI,QAAEA,EAASC,UAAAA,GAAcN,EAA2BC,EAAS,SAClDI,EAAQ4B,WAAW,uBAGlCjB,EAASf,EAAS,KAAMA,EAASI,EAASC,GAAW,EAAML,KAKjE,MAAMP,EAA0BzM,OAAOiP,YACrCjP,OAAOkP,QAAQ1C,GAAUnJ,IAAI,EAAE5B,EAAG0N,KAAO,CAAC1N,EAAG0N,EAAEV,SAE3C/B,EAA0B1M,OAAOiP,YACrCjP,OAAOkP,QAAQ1C,GAAUnJ,IAAI,EAAE5B,EAAG0N,KAAO,CAAC1N,EAAG0N,EAAE9B,aAGjD,MAAO,CAAEd,sBAAAA,EAAuBC,SAAUC,EAAyBC,wBAAAA,IAElE,CAACR,EAAkBC,EAAkBxN,EAAuBD,EAAUU,IAElE,MAAA,CACLA,kBACAO,iBACAC,iBACAC,iBACAoM,eACAC,mBACAC,mBACAE,gBACAE,wBACAE,0BACAC,0BACA5M"}
|
|
1
|
+
{"version":3,"file":"useCompareData.js","sources":["../../../../../src/features/CognitiveCompare/hooks/useCompareData.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { getSideData, getRationale, hasValue, safeStringify, isMissingStr, DEVIATION_BADGE_SEPARATOR, resolveComparisonInputItems } from \"../CognitiveComparehelpers\";\nimport { ComparisonRow, SectionBlock, ProposedRuleData, RuleData, ComparisonConfig } from \"../CognitiveCompareTypes\";\nimport { buildComparisonRows } from \"../utils/buildComparisonRows\";\n\nconst DEFAULT_RULE_FALLBACK: RuleData = { id: \"\", title: \"\", similarity: 0, sections: [] };\n\nexport const useCognitiveTreeData = (\n treeData: Record<string, any> | undefined,\n maintainRelativeOrder: boolean,\n deviationData: Record<string, any> | null,\n resolvedComparisonConfig: ComparisonConfig,\n enableDeviationSchemaBackwardCompatibility: boolean = true,\n guidelinesData?: Record<string, any> | null\n) => {\n // AdaptTreeData function \n // memoized to increase performance\n // Stabilize the deviationData reference by stringifying it.\n // This prevents React from triggering re-renders purely due to memory reference changes.\n // We keep accepting it as a string so the memo dep stays content-based.\n const deviationDataStr = typeof deviationData === \"string\" ? deviationData : JSON.stringify(deviationData || {});\n\n // ── NEW: Check for either the new learnings_data or the old artifactData ──\n const isGuidelineMode = Boolean(\n guidelinesData && \n (guidelinesData.learnings_data || guidelinesData.data?.artifactData?.userStorySnapshot)\n );\n\n const { activeProposed, activeVariants, comparisonRows, parseError } = useMemo(() => {\n if (!treeData || Object.keys(treeData).length === 0) {\n return {\n activeProposed: {} as ProposedRuleData,\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: \"Tree data is required\",\n };\n }\n const stableDeviationData = JSON.parse(deviationDataStr);\n\n try {\n const nodes = treeData.nodes || treeData;\n let baseSections: any[] = []; \n let refSections: any[] = []; \n let comparisonRows: ComparisonRow[] = [];\n\n const rootId = treeData.base_root_id;\n const indexMap = treeData.input_index_map || { \"0\": \"left\", \"1\": \"right\" };\n const rootNode = treeData[rootId] || nodes[rootId];\n\n if (!rootNode || rootNode.display_node === false) {\n return {\n activeProposed: { title: \"No Data\", sections: [] },\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: null,\n };\n }\n \n const contentMapping = treeData.content_mapping || {};\n const getNode = (nodeId: string) => treeData[nodeId] || nodes[nodeId];\n \n\n const normalizeEvaluationResult = (rawEvaluationResult: any, nodeLeftId: string, nodeRightId: string) => {\n if (!rawEvaluationResult || typeof rawEvaluationResult !== \"object\") {\n return rawEvaluationResult || null;\n }\n\n // Old format already supported by UI.\n if (rawEvaluationResult.deviations) {\n return rawEvaluationResult;\n }\n\n if (enableDeviationSchemaBackwardCompatibility) {\n return rawEvaluationResult;\n }\n\n const numericDeviationKeys = Object.keys(rawEvaluationResult).filter(\n (k) => /^\\d+$/.test(k),\n );\n\n if (!numericDeviationKeys.length) {\n return rawEvaluationResult;\n }\n\n const sortedDeviationKeys = numericDeviationKeys.sort(\n (a, b) => Number(a) - Number(b),\n );\n const normalizedDeviations: Record<string, any> = {};\n const deviationEntries: Record<string, any> = {};\n let firstEntry: any = null;\n\n sortedDeviationKeys.forEach((devKey) => {\n const entry = rawEvaluationResult[devKey];\n if (!entry || typeof entry !== \"object\") return;\n if (!firstEntry) firstEntry = entry;\n\n const shouldShowHighlights =\n !entry?.status || entry.status === \"pending\";\n const deviationHighlight =\n entry?.deviation_highlight ||\n entry?.web_search_answer?.deviation_highlight;\n\n const citationHighlights = (docId: string): string[] => {\n const citations = entry?.cognitive_decisioning?.citations || entry?.citations || {};\n return Object.values(citations)\n .map((citation: any) => citation?.[docId]?.highlighted_text)\n .filter((text: any) => typeof text === \"string\" && text.trim().length > 0);\n };\n\n const firstNonEmpty = (...values: any[]): string[] => {\n for (const value of values) {\n if (Array.isArray(value) && value.some((text) => !isMissingStr(text))) {\n return value;\n }\n }\n return [];\n };\n\n const leftHighlights: string[] = shouldShowHighlights\n ? firstNonEmpty(\n entry?.deviation_highlights?.[nodeLeftId] ||\n entry?.deviation_highlights?.[indexMap[\"0\"] as string],\n typeof deviationHighlight === \"string\"\n ? [deviationHighlight]\n : [],\n citationHighlights(nodeLeftId),\n citationHighlights(indexMap[\"0\"] as string),\n )\n : [];\n\n const rightHighlights: string[] = shouldShowHighlights\n ? firstNonEmpty(\n entry?.deviation_highlights?.[nodeRightId] ||\n entry?.deviation_highlights?.[indexMap[\"1\"] as string],\n citationHighlights(nodeRightId),\n citationHighlights(indexMap[\"1\"] as string),\n )\n : [];\n\n normalizedDeviations[devKey] = {\n [indexMap[\"0\"] as string]: leftHighlights[0] || \"\", \n [indexMap[\"1\"] as string]: rightHighlights[0] || \"\",\n deviation_summary: entry?.deviation_summary || \"\",\n deviation_title: entry?.deviation_title,\n deviation_impact: entry?.deviation_impact,\n deviation_explanation: entry?.deviation_explanation,\n evaluation_outputs: entry?.evaluation_outputs,\n cognitive_decisioning: entry?.cognitive_decisioning,\n deviation_highlights: entry?.deviation_highlights,\n };\n\n deviationEntries[devKey] = entry;\n });\n\n return {\n ...rawEvaluationResult,\n deviation_title: firstEntry?.deviation_title || rawEvaluationResult?.deviation_title,\n deviation_impact: firstEntry?.deviation_impact || rawEvaluationResult?.deviation_impact,\n deviation_summary: firstEntry?.deviation_summary || rawEvaluationResult?.deviation_summary,\n deviation_explanation:\n firstEntry?.deviation_explanation || rawEvaluationResult?.deviation_explanation,\n evaluation_outputs:\n firstEntry?.evaluation_outputs || rawEvaluationResult?.evaluation_outputs,\n cognitive_decisioning:\n firstEntry?.cognitive_decisioning || rawEvaluationResult?.cognitive_decisioning,\n deviations: normalizedDeviations,\n deviation_entries: deviationEntries,\n };\n };\n\n // UNIVERSAL RE-ROUTING ENGINE (WITH SORTING FIX)\n const reRouteRHSTree = (sections: any[]) => {\n const allNodesMap = new Map<string, any>();\n \n const indexNodes = (nodes: any[]) => {\n nodes.forEach(node => {\n if (node.id) allNodesMap.set(node.id, node);\n if (node.subsections?.length) indexNodes(node.subsections);\n });\n };\n indexNodes(sections);\n \n const moveNodes = (nodes: any[], parentNode?: any): any[] => {\n let filteredNodes: any[] = [];\n \n for (const node of nodes) {\n const targetParentId = node.ref_parent_section_node_id;\n \n if (targetParentId && allNodesMap.has(targetParentId) && targetParentId !== parentNode?.id) {\n const targetParent = allNodesMap.get(targetParentId)!;\n if (!targetParent.subsections) targetParent.subsections = [];\n \n if (!targetParent.subsections.some((s: any) => s.id === node.id)) {\n targetParent.subsections.push(node);\n }\n } else {\n if (node.subsections?.length) {\n node.subsections = moveNodes(node.subsections, node);\n }\n filteredNodes.push(node);\n }\n }\n return filteredNodes;\n };\n \n const finalSections = moveNodes(sections);\n\n // Sort step added to ensure display_index is respected after re-routing\n const sortSubsections = (nodes: any[]) => {\n nodes.forEach(node => {\n if (node.subsections && node.subsections.length > 0) {\n node.subsections.sort((a: any, b: any) => {\n if (a.selfIndex < 0 && b.selfIndex >= 0) return 1;\n if (a.selfIndex >= 0 && b.selfIndex < 0) return -1;\n return (a.selfIndex || 0) - (b.selfIndex || 0);\n });\n sortSubsections(node.subsections);\n }\n });\n };\n\n sortSubsections(finalSections);\n return finalSections;\n };\n\n const getNodeInputIds = (node: any) => {\n const nodeInputKeys = node.comparison_inputs ? Object.keys(node.comparison_inputs) : [];\n let nodeLeftId = indexMap[\"0\"];\n let nodeRightId = indexMap[\"1\"];\n\n if (nodeInputKeys.length > 0) {\n nodeLeftId = nodeInputKeys.includes(indexMap[\"0\"]) ? indexMap[\"0\"] : nodeInputKeys[0];\n nodeRightId = nodeInputKeys.includes(indexMap[\"1\"]) ? indexMap[\"1\"] : (nodeInputKeys.length > 1 ? nodeInputKeys[1] : nodeInputKeys[0]);\n }\n\n return { nodeLeftId, nodeRightId };\n };\n\n const getParentContentId = (attrs: any) =>\n attrs?.entity_id ||\n attrs?.ref_parent_section_node_id ||\n attrs?.parent_entity_id ||\n null;\n\n const makeSectionBlock = (\n nodeId: string,\n item: any,\n evaluationResult: any,\n rationale: any,\n ): SectionBlock => {\n const attrs = item.attributes || {};\n const data = item.data || {};\n const displayTitle = attrs.display_title !== false;\n const displayContent = attrs.display_content !== false;\n const title = displayTitle ? safeStringify(data.title || \"\") : \"\";\n const content = displayContent ? safeStringify(data.content || \"\") : \"\";\n const changeHistory = displayContent ? safeStringify(data.change_history || \"\") : \"\";\n const selfIndex =\n attrs.display_index !== undefined && attrs.display_index !== null\n ? Number(attrs.display_index)\n : -1;\n const parentContentId = getParentContentId(attrs);\n const hasData = !!(title.trim() || content.trim());\n\n return {\n id: `${nodeId}::${item.contentId}`,\n nodeId,\n contentId: item.contentId,\n parentContentId,\n title,\n content,\n change_history: changeHistory,\n displayTitle,\n displayContent,\n subsections: [],\n ...(hasData ? rationale : { score: undefined, relation: \"not_defined\" }),\n evaluationResult,\n evaluationResults: evaluationResult ? [evaluationResult] : [],\n selfIndex,\n refIndexes: [],\n refContentIds: [],\n ref_parent_section_node_id: parentContentId,\n } as SectionBlock;\n };\n\n const mergeBlock = (target: any, incoming: any) => {\n target.refIndexes = Array.from(new Set([...(target.refIndexes || []), ...(incoming.refIndexes || [])]));\n target.refContentIds = Array.from(new Set([...(target.refContentIds || []), ...(incoming.refContentIds || [])]));\n\n const existingChildKeys = new Set(\n (target.subsections || []).map((child: any) =>\n child.id || child.contentId || child.nodeId,\n ),\n );\n (incoming.subsections || []).forEach((child: any) => {\n const childKey = child.id || child.contentId || child.nodeId;\n if (!existingChildKeys.has(childKey)) {\n target.subsections = [...(target.subsections || []), child];\n existingChildKeys.add(childKey);\n }\n });\n\n const mergedEvaluationResults = [\n ...(target.evaluationResults || (target.evaluationResult ? [target.evaluationResult] : [])),\n ...(incoming.evaluationResults || (incoming.evaluationResult ? [incoming.evaluationResult] : [])),\n ].filter(Boolean);\n const seenEvaluationResults = new Set<string>();\n target.evaluationResults = mergedEvaluationResults.filter((result: any) => {\n const key = result?.nodeId || JSON.stringify(Object.keys(result?.deviations || result || {}));\n if (seenEvaluationResults.has(key)) return false;\n seenEvaluationResults.add(key);\n return true;\n });\n\n if (!target.evaluationResult && incoming.evaluationResult) target.evaluationResult = incoming.evaluationResult;\n if (!target.cognitiveData && incoming.cognitiveData) target.cognitiveData = incoming.cognitiveData;\n\n return target;\n };\n\n const sortFn = (a: any, b: any) => {\n if (a.selfIndex! < 0 && b.selfIndex! >= 0) return 1;\n if (a.selfIndex! >= 0 && b.selfIndex! < 0) return -1;\n return a.selfIndex! - b.selfIndex!;\n };\n\n const buildSideSections = (nodeId: string, sideIndex: \"0\" | \"1\"): SectionBlock[] => {\n const node = getNode(nodeId);\n if (!node || node.display_node === false) return [];\n \n if (isGuidelineMode && sideIndex === \"1\") return [];\n\n const { nodeLeftId, nodeRightId } = getNodeInputIds(node);\n const rationale = getRationale(node);\n const rawEvaluationResult =\n stableDeviationData?.[nodeId]?.evaluation_result || node.evaluation_result || null;\n const normalizedEvaluationResult = normalizeEvaluationResult(rawEvaluationResult, nodeLeftId, nodeRightId);\n const evaluationResult = normalizedEvaluationResult && typeof normalizedEvaluationResult === \"object\"\n ? { ...normalizedEvaluationResult, nodeId }\n : normalizedEvaluationResult;\n const items = resolveComparisonInputItems(node, sideIndex, indexMap, contentMapping);\n\n const sections = items.map((item) =>\n makeSectionBlock(nodeId, item, evaluationResult, rationale),\n );\n\n if (node.next) {\n const childSections = (Object.values(node.next) as string[]).flatMap((childId) =>\n buildSideSections(childId, sideIndex),\n );\n sections.forEach((section) => {\n const matchedChildren = childSections.filter((child: any) =>\n !child.parentContentId ||\n child.parentContentId === section.contentId ||\n child.parentContentId === section.parentContentId,\n );\n section.subsections = matchedChildren.length ? matchedChildren : childSections;\n });\n }\n\n return sections;\n };\n\n if (!maintainRelativeOrder) {\n if (rootNode.next) {\n (Object.values(rootNode.next) as string[]).forEach((nodeId) => {\n const node = getNode(nodeId);\n if (!node || node.display_node === false) return;\n\n const leftBlocks = buildSideSections(nodeId, \"0\");\n\n if (isGuidelineMode) {\n baseSections.push(...leftBlocks);\n return;\n }\n\n const rightBlocks = reRouteRHSTree(buildSideSections(nodeId, \"1\"));\n comparisonRows.push(\n ...buildComparisonRows(nodeId, leftBlocks, rightBlocks),\n );\n });\n }\n\n if (!isGuidelineMode) {\n baseSections = comparisonRows.map((row) => row.left);\n refSections = comparisonRows.map((row) => row.right);\n }\n\n } else {\n const buildRelativeOrderMapping = (nodeMap?: Record<string, string> | null, depth = 0) => {\n let refSections: SectionBlock[] = [];\n let baseSections: SectionBlock[] = [];\n if (!nodeMap) return { refSections, baseSections };\n \n const rightNodesHash: Record<string, SectionBlock> = {};\n const leftNodesHash: Record<string, SectionBlock> = {};\n let rightNodeOrphanIdx = -1;\n let leftNodeOrphanIdx = -1;\n\n for (const nodeIdx in nodeMap) {\n const nodeId = nodeMap[nodeIdx];\n const node = getNode(nodeId);\n if (!node || node.display_node === false) continue;\n\n const { nodeLeftId, nodeRightId } = getNodeInputIds(node);\n const rationale = getRationale(node);\n const rawEvaluationResult = stableDeviationData?.[nodeId]?.evaluation_result || node.evaluation_result || null;\n const normalizedEvaluationResult = normalizeEvaluationResult(rawEvaluationResult, nodeLeftId, nodeRightId);\n const evaluationResult = normalizedEvaluationResult && typeof normalizedEvaluationResult === \"object\"\n ? { ...normalizedEvaluationResult, nodeId }\n : normalizedEvaluationResult;\n\n const { refSections: refSubSections, baseSections: baseSubSections } = buildRelativeOrderMapping(node.next, depth + 1);\n\n const leftItems = resolveComparisonInputItems(node, \"0\", indexMap, contentMapping);\n const leftBlocks = leftItems.map((item) => {\n const block = makeSectionBlock(nodeId, item, evaluationResult, rationale);\n if (block.selfIndex === -1) block.selfIndex = leftNodeOrphanIdx--;\n return block;\n });\n\n let rightBlocks: any[] = [];\n if (!isGuidelineMode) {\n const rightItems = resolveComparisonInputItems(node, \"1\", indexMap, contentMapping);\n rightBlocks = rightItems.map((item) => {\n const block = makeSectionBlock(nodeId, item, evaluationResult, rationale);\n if (block.selfIndex === -1) block.selfIndex = rightNodeOrphanIdx--;\n return block;\n });\n }\n\n leftBlocks.forEach((leftBlock: any) => {\n rightBlocks.forEach((rightBlock: any) => {\n if (Number(rightBlock.selfIndex) >= 0 && Number(leftBlock.selfIndex) >= 0) {\n if (!rightBlock.refIndexes?.includes(Number(leftBlock.selfIndex))) rightBlock.refIndexes?.push(Number(leftBlock.selfIndex));\n if (!leftBlock.refIndexes?.includes(Number(rightBlock.selfIndex))) leftBlock.refIndexes?.push(Number(rightBlock.selfIndex));\n }\n if (leftBlock.contentId && !rightBlock.refContentIds?.includes(leftBlock.contentId)) rightBlock.refContentIds?.push(leftBlock.contentId);\n if (rightBlock.contentId && !leftBlock.refContentIds?.includes(rightBlock.contentId)) leftBlock.refContentIds?.push(rightBlock.contentId);\n });\n });\n\n rightBlocks.forEach((rightBlock: any) => {\n const matchedSubSections = refSubSections.filter((sub: any) =>\n !sub.parentContentId ||\n sub.parentContentId === rightBlock.contentId ||\n sub.parentContentId === rightBlock.parentContentId ||\n rightBlock.refContentIds?.includes(sub.parentContentId),\n );\n if (matchedSubSections.length > 0) rightBlock.subsections = matchedSubSections;\n\n const rightHashKey = depth === 0\n ? String(rightBlock.selfIndex)\n : `${rightBlock.selfIndex}_${rightBlock.contentId || nodeId}`;\n rightNodesHash[rightHashKey] = rightNodesHash[rightHashKey]\n ? mergeBlock(rightNodesHash[rightHashKey], rightBlock)\n : rightBlock;\n });\n\n leftBlocks.forEach((leftBlock: any) => {\n const matchedSubSections = baseSubSections.filter((sub: any) =>\n !sub.parentContentId ||\n sub.parentContentId === leftBlock.contentId ||\n sub.parentContentId === leftBlock.parentContentId ||\n leftBlock.refContentIds?.includes(sub.parentContentId),\n );\n if (matchedSubSections.length > 0) leftBlock.subsections = matchedSubSections;\n\n const leftHashKey = depth === 0\n ? String(leftBlock.selfIndex)\n : `${leftBlock.selfIndex}_${leftBlock.contentId || nodeId}`;\n leftNodesHash[leftHashKey] = leftNodesHash[leftHashKey]\n ? mergeBlock(leftNodesHash[leftHashKey], leftBlock)\n : leftBlock;\n });\n }\n\n refSections = Object.values(rightNodesHash);\n baseSections = Object.values(leftNodesHash);\n\n refSections.sort(sortFn);\n baseSections.sort(sortFn);\n\n return { refSections, baseSections };\n };\n\n const { refSections: righSections, baseSections: leftSections } = buildRelativeOrderMapping(rootNode.next);\n \n if (!isGuidelineMode) {\n refSections = reRouteRHSTree(righSections);\n }\n baseSections = leftSections;\n }\n\n const rootLeftData = getSideData(rootNode, \"0\", indexMap, contentMapping);\n const rootRightData = getSideData(rootNode, \"1\", indexMap, contentMapping);\n\n const activeProposed: ProposedRuleData = {\n title: rootLeftData.title || \"Uploaded Contract\",\n description: rootNode.decision_scope_description || \"\",\n sections: baseSections,\n };\n\n // ── NEW: Extract the title dynamically based on the new learnings_data structure ──\n const getGuidelineTitle = () => {\n if (guidelinesData?.learnings_data && Object.keys(guidelinesData.learnings_data).length > 0) {\n const firstKey = Object.keys(guidelinesData.learnings_data)[0];\n return guidelinesData.learnings_data[firstKey]?.title || \"Rulebook Guidelines\";\n }\n return guidelinesData?.data?.artifactTitle || \"Rulebook Guidelines\";\n };\n\n const activeVariant: RuleData = {\n id: \"tree-variant-1\",\n title: isGuidelineMode ? getGuidelineTitle() : (rootRightData.title || \"Reference Template\"),\n similarity: 0,\n sections: refSections,\n analysis: { rule_difference_comparison: { summary: { overall_score: 0, overall_summary: rootNode.decision_scope_description || \"\" }, fields: {} } },\n };\n\n return {\n activeProposed,\n activeVariants: [activeVariant],\n comparisonRows,\n parseError: null,\n };\n } catch (err: unknown) {\n console.error(\"Data Transformation Error: \", err);\n return {\n activeProposed: {} as ProposedRuleData,\n activeVariants: [],\n comparisonRows: [] as ComparisonRow[],\n parseError: err instanceof Error ? err.message : \"Unknown Parsing Error\",\n };\n }\n }, [treeData, maintainRelativeOrder, deviationDataStr, enableDeviationSchemaBackwardCompatibility, guidelinesData]);\n\n // 2. Extracted section references\n const existingRule = activeVariants?.[0] || DEFAULT_RULE_FALLBACK;\n \n const proposedSections = useMemo(\n () => (activeProposed?.sections || []) as SectionBlock[],\n [activeProposed?.sections]\n );\n \n const existingSections = useMemo(\n () => (existingRule.sections || []) as SectionBlock[],\n [existingRule.sections]\n );\n\n const hasSectionAccordions =\n proposedSections.length > 0 || existingSections.length > 0;\n\n const visibleFields = useMemo(() => {\n return resolvedComparisonConfig.fields.filter(({ key }) => {\n if (hasSectionAccordions && key === \"description\") return false;\n return hasValue(activeProposed?.[key as keyof ProposedRuleData]) || hasValue(existingRule[key as keyof RuleData]);\n });\n }, [activeProposed, existingRule, hasSectionAccordions, resolvedComparisonConfig.fields]);\n\n // @ts-ignore\n const { parentDeviationRecord, registry: deviationNumberRegistry, deviationParentRegistry } = useMemo(() => {\n const parentDeviationRecord: Record<string, SectionBlock[]> = {};\n const registry: Record<string, { index: number; rootKey: string; parentNum: number }> = {};\n const counters: Record<string, number> = {};\n // Add a fallback id counter to ensure no deviations are left without ID even when backend does not provide any id.\n let fallbackIdCounter = 0;\n const leftDocId = treeData?.input_index_map?.[\"0\"];\n const rightDocId = treeData?.input_index_map?.[\"1\"];\n\n const resolveRootKeyAndParentNum = (\n rootSec: SectionBlock,\n side: \"left\" | \"right\",\n ): { rootKey: string; parentNum: number } => {\n if (!maintainRelativeOrder) {\n const idx = side === \"left\"\n ? proposedSections.indexOf(rootSec)\n : existingSections.indexOf(rootSec);\n return { rootKey: `${side}:${idx}`, parentNum: idx + 1 };\n }\n\n if (side === \"left\") {\n const selfIdx = (rootSec as any).selfIndex;\n const parentNum = selfIdx !== undefined && selfIdx >= 0 \n ? selfIdx + 1 \n : proposedSections.indexOf(rootSec) + 1;\n return { rootKey: `left-root:${rootSec.id}`, parentNum };\n }\n\n const rhsSelfIndex = (rootSec as any).selfIndex;\n const mappedLhs = proposedSections.find(\n (l: any) => l.refIndexes?.includes(rhsSelfIndex),\n );\n\n if (mappedLhs) {\n const lhsSelfIdx = (mappedLhs as any).selfIndex;\n const parentNum = lhsSelfIdx !== undefined && lhsSelfIdx >= 0 \n ? lhsSelfIdx + 1 \n : proposedSections.indexOf(mappedLhs) + 1;\n return { rootKey: `left-root:${mappedLhs.id}`, parentNum };\n }\n\n // True RHS orphan\n const parentNum = rhsSelfIndex !== undefined && rhsSelfIndex >= 0 \n ? rhsSelfIndex + 1 \n : existingSections.indexOf(rootSec) + 1;\n return { rootKey: `right-orphan-root:${rootSec.id}`, parentNum };\n };\n\n const processDeviations = (evalNode: any, rootKey: string, parentNum: number) => {\n const evaluationResults = evalNode?.evaluationResults?.length\n ? evalNode.evaluationResults\n : (evalNode?.evaluationResult ? [evalNode.evaluationResult] : []);\n\n evaluationResults.forEach((evaluationResult: any) => {\n const deviations = evaluationResult?.deviations || {};\n\n Object.keys(deviations).sort().forEach(devKey => {\n const devMap = deviations[devKey];\n if (!devMap) return;\n\n // changed the code because this logic was too strict and missed\n // cases where highlights were present in normalized/citation-backed data.\n const hasLeftHighlight = !isMissingStr(devMap[leftDocId as string]);\n const hasRightHighlight = !isMissingStr(devMap[rightDocId as string]);\n if (hasLeftHighlight || hasRightHighlight) {\n const registryNodeId = evaluationResult?.nodeId || evalNode.nodeId || evalNode.id;\n const refId = `${registryNodeId}${DEVIATION_BADGE_SEPARATOR}${devKey}`;\n if (registry[refId] === undefined) {\n if (counters[rootKey] === undefined) counters[rootKey] = 1;\n registry[refId] = { index: counters[rootKey]++, rootKey, parentNum };\n }\n }\n });\n });\n };\n\n // Resolve the correct child node at each level using id/refIndexes matching\n // rather than blind array-position (`subsections[i]`), so cross-routed\n // subsections are attributed to their actual structural parent.\n const findMatchingChild = (\n children: SectionBlock[] | undefined,\n target: SectionBlock | undefined,\n ): SectionBlock | undefined => {\n if (!children || !target) return undefined;\n return children.find((c: any) =>\n c.id === target.id ||\n (c.nodeId && c.nodeId === (target as any).nodeId) ||\n (c.contentId && c.contentId === (target as any).contentId)\n ) || undefined;\n };\n\n const traverse = (\n leftNode: SectionBlock | undefined | null,\n evalNode: SectionBlock | undefined | null,\n rightNode: SectionBlock | undefined | null,\n rootKey: string,\n parentNum: number,\n isRoot: boolean,\n parentNode: SectionBlock,\n ) => {\n if (evalNode) {\n processDeviations(evalNode, rootKey, parentNum);\n }\n\n if (evalNode && !isRoot) {\n const safeParentId = parentNode?.id || `fallback_parent_${fallbackIdCounter++}`;\n if (!parentDeviationRecord[safeParentId]) {\n parentDeviationRecord[safeParentId] = [];\n }\n parentDeviationRecord[safeParentId].push(evalNode);\n }\n\n const subs = evalNode?.subsections || leftNode?.subsections || rightNode?.subsections || [];\n subs.forEach((childEvalNode: any) => {\n const matchedLeft = findMatchingChild(leftNode?.subsections, childEvalNode);\n const matchedRight = findMatchingChild(rightNode?.subsections, childEvalNode);\n traverse(\n childEvalNode,\n matchedLeft,\n matchedRight,\n rootKey,\n parentNum,\n false,\n evalNode || parentNode,\n );\n });\n };\n\n proposedSections.forEach((rootSec) => {\n const { rootKey, parentNum } = resolveRootKeyAndParentNum(rootSec, \"left\");\n let rightSec = null;\n if (maintainRelativeOrder) {\n const rhsSelfIndex = (rootSec as any).refIndexes?.[0];\n rightSec = existingSections.find(s => (s as any).selfIndex === rhsSelfIndex);\n } else {\n rightSec = existingSections[proposedSections.indexOf(rootSec)];\n }\n traverse(rootSec, rootSec, rightSec, rootKey, parentNum, true, rootSec);\n });\n\n if (!isGuidelineMode) {\n existingSections.forEach((rootSec) => {\n const { rootKey, parentNum } = resolveRootKeyAndParentNum(rootSec, \"right\");\n const isOrphan = rootKey.startsWith(\"right-orphan-root:\");\n\n if (isOrphan) {\n traverse(rootSec, null, rootSec, rootKey, parentNum, true, rootSec);\n }\n });\n }\n\n const deviationNumberRegistry = Object.fromEntries(\n Object.entries(registry).map(([k, v]) => [k, v.index])\n );\n const deviationParentRegistry = Object.fromEntries(\n Object.entries(registry).map(([k, v]) => [k, v.parentNum])\n );\n\n return { parentDeviationRecord, registry: deviationNumberRegistry, deviationParentRegistry };\n\n }, [proposedSections, existingSections, maintainRelativeOrder, treeData, isGuidelineMode]);\n\n return {\n isGuidelineMode, // ── NEW ──\n activeProposed,\n activeVariants,\n comparisonRows,\n existingRule,\n proposedSections,\n existingSections,\n visibleFields,\n parentDeviationRecord,\n deviationNumberRegistry,\n deviationParentRegistry,\n parseError\n };\n};\n"],"names":["DEFAULT_RULE_FALLBACK","id","title","similarity","sections","treeData","maintainRelativeOrder","deviationData","resolvedComparisonConfig","enableDeviationSchemaBackwardCompatibility","guidelinesData","deviationDataStr","JSON","stringify","isGuidelineMode","Boolean","learnings_data","data","artifactData","userStorySnapshot","activeProposed","activeVariants","comparisonRows","parseError","useMemo","Object","keys","length","stableDeviationData","parse","nodes","baseSections","refSections","rootId","base_root_id","indexMap","input_index_map","rootNode","display_node","contentMapping","content_mapping","getNode","nodeId","normalizeEvaluationResult","rawEvaluationResult","nodeLeftId","nodeRightId","deviations","numericDeviationKeys","filter","k","test","sortedDeviationKeys","sort","a","b","Number","normalizedDeviations","deviationEntries","firstEntry","forEach","devKey","entry","shouldShowHighlights","status","deviationHighlight","deviation_highlight","web_search_answer","citationHighlights","docId","citations","cognitive_decisioning","values","map","citation","highlighted_text","text","trim","firstNonEmpty","value","Array","isArray","some","isMissingStr","leftHighlights","deviation_highlights","rightHighlights","deviation_summary","deviation_title","deviation_impact","deviation_explanation","evaluation_outputs","deviation_entries","reRouteRHSTree","allNodesMap","Map","indexNodes","node","set","subsections","moveNodes","parentNode","filteredNodes","targetParentId","ref_parent_section_node_id","has","targetParent","get","s","push","finalSections","sortSubsections","selfIndex","getNodeInputIds","nodeInputKeys","comparison_inputs","includes","getParentContentId","attrs","entity_id","parent_entity_id","makeSectionBlock","item","evaluationResult","rationale","attributes","displayTitle","display_title","displayContent","display_content","safeStringify","content","changeHistory","change_history","display_index","parentContentId","hasData","contentId","score","relation","evaluationResults","refIndexes","refContentIds","mergeBlock","target","incoming","from","Set","existingChildKeys","child","childKey","add","mergedEvaluationResults","seenEvaluationResults","result","key","cognitiveData","sortFn","buildSideSections","sideIndex","getRationale","evaluation_result","normalizedEvaluationResult","resolveComparisonInputItems","next","childSections","flatMap","childId","section","matchedChildren","buildRelativeOrderMapping","nodeMap","depth","rightNodesHash","leftNodesHash","rightNodeOrphanIdx","leftNodeOrphanIdx","nodeIdx","refSubSections","baseSubSections","leftBlocks","block","rightBlocks","rightItems","leftBlock","rightBlock","matchedSubSections","sub","rightHashKey","String","leftHashKey","righSections","leftSections","buildComparisonRows","row","left","right","rootLeftData","getSideData","rootRightData","description","decision_scope_description","firstKey","artifactTitle","getGuidelineTitle","analysis","rule_difference_comparison","summary","overall_score","overall_summary","fields","err","console","error","Error","message","existingRule","proposedSections","existingSections","hasSectionAccordions","visibleFields","hasValue","parentDeviationRecord","registry","deviationNumberRegistry","deviationParentRegistry","counters","fallbackIdCounter","leftDocId","rightDocId","resolveRootKeyAndParentNum","rootSec","side","idx","indexOf","rootKey","parentNum","selfIdx","rhsSelfIndex","mappedLhs","find","l","lhsSelfIdx","findMatchingChild","children","c","traverse","leftNode","evalNode","rightNode","isRoot","devMap","hasLeftHighlight","hasRightHighlight","refId","DEVIATION_BADGE_SEPARATOR","index","processDeviations","safeParentId","childEvalNode","matchedLeft","matchedRight","rightSec","startsWith","fromEntries","entries","v"],"mappings":"mLAKA,MAAMA,EAAkC,CAAEC,GAAI,GAAIC,MAAO,GAAIC,WAAY,EAAGC,SAAU,iCAElD,CAClCC,EACAC,EACAC,EACAC,EACAC,GAAsD,EACtDC,KAOM,MAAAC,EAA4C,iBAAlBJ,EAA6BA,EAAgBK,KAAKC,UAAUN,GAAiB,CAAA,GAGvGO,EAAkBC,QACtBL,IACCA,EAAeM,gBAAkBN,EAAeO,MAAMC,cAAcC,qBAGjEC,eAAEA,EAAgBC,eAAAA,EAAAC,eAAgBA,aAAgBC,GAAeC,EAAAA,QAAQ,KAC7E,IAAKnB,GAA6C,IAAjCoB,OAAOC,KAAKrB,GAAUsB,OAC9B,MAAA,CACLP,eAAgB,CAAC,EACjBC,eAAgB,GAChBC,eAAgB,GAChBC,WAAY,yBAGV,MAAAK,EAAsBhB,KAAKiB,MAAMlB,GAEnC,IACI,MAAAmB,EAAQzB,EAASyB,OAASzB,EAChC,IAAI0B,EAAsB,GACtBC,EAAqB,GACrBV,EAAkC,GAEtC,MAAMW,EAAS5B,EAAS6B,aAClBC,EAAW9B,EAAS+B,iBAAmB,CAAE,EAAK,OAAQ,EAAK,SAC3DC,EAAWhC,EAAS4B,IAAWH,EAAMG,GAE3C,IAAKI,IAAsC,IAA1BA,EAASC,aACjB,MAAA,CACLlB,eAAgB,CAAElB,MAAO,UAAWE,SAAU,IAC9CiB,eAAgB,GAChBC,eAAgB,GAChBC,WAAY,MAIV,MAAAgB,EAAiBlC,EAASmC,iBAAmB,GAC7CC,EAAWC,GAAmBrC,EAASqC,IAAWZ,EAAMY,GAGxDC,EAA4B,CAACC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AML,KAG5DzN,GACc4M,EAAA9J,QAAS2K,IACxB,MAAMI,QAAEA,EAASC,UAAAA,GAAcN,EAA2BC,EAAS,SAClDI,EAAQ4B,WAAW,uBAGlCjB,EAASf,EAAS,KAAMA,EAASI,EAASC,GAAW,EAAML,KAKjE,MAAMP,EAA0BvM,OAAO+O,YACrC/O,OAAOgP,QAAQ1C,GAAUtJ,IAAI,EAAEvB,EAAGwN,KAAO,CAACxN,EAAGwN,EAAEV,SAE3C/B,EAA0BxM,OAAO+O,YACrC/O,OAAOgP,QAAQ1C,GAAUtJ,IAAI,EAAEvB,EAAGwN,KAAO,CAACxN,EAAGwN,EAAE9B,aAGjD,MAAO,CAAEd,sBAAAA,EAAuBC,SAAUC,EAAyBC,wBAAAA,IAElE,CAACR,EAAkBC,EAAkBpN,EAAuBD,EAAUS,IAElE,MAAA,CACLA,kBACAM,iBACAC,iBACAC,iBACAkM,eACAC,mBACAC,mBACAE,gBACAE,wBACAE,0BACAC,0BACA1M"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("../CognitiveComparehelpers.js"),n=require("../Guidelines/utils/guidelineTargets.js");exports.useLinesCalculator=({containerRef:r,leftContainerRef:i,rightContainerRef:c,svgContainerRef:l,pathRefs:u,leftHeaderRef:s,rightHeaderRef:o,proposedSections:g,existingSections:h,visibleFields:a,leftRefs:d,rightRefs:f,sectionLeftRefs:p,sectionRightRefs:b,subSectionLeftRefs:A,subSectionRightRefs:y,lhsBadgeRefs:$,rhsBadgeRefs:R,sectionRowRefs:x,expandedSections:m,expandedSubSections:B,connectedSections:S,isSideBySide:T,activeSideBySideSection:I,maintainRelativeOrder:C,isGuidelineMode:E,cognitiveMap:M,getSectionCompareStyle:v,getSubSectionCompareStyle:D,getDeviationStyleByKey:O,isArrowVisible:L,isAnimatingRef:_,isSideBySideRef:F,sideBySideCacheRef:N,sideBySideLineRef:H,activeSideBySideSectionRef:P,activeSideBySideRightSectionRef:k,connectedLines:w,setConnectedLines:G,cachedConnectedPositions:V,calculateLinesRef:Y,resizeTimerRef:j,scrollLock:z,scrollSyncLocked:Q,handleResizeRef:X,activeProposed:q,existingRule:K,analysisData:J,pendingScrollTargetRef:U,pendingScrollCallbackRef:W,resolvedComparisonConfig:Z,getFieldData:tt})=>{const[et,nt]=t.useState([]),[rt,it]=t.useState(null),[ct,lt]=t.useState([]),ut=w??ct,st=G??lt,[ot,gt]=t.useState({width:0,height:0}),ht=t.useRef(!1),at=t.useRef(!1),dt=t.useRef(!1),ft=t.useRef(null),pt=t.useRef([]),bt=V??pt,At=(t,e,n,r,i,c,l)=>{if(Math.abs(r-e)<=1)return c&&l?`M ${t},${e} L ${n},${r}`:c&&!l?`M ${t},${e} L ${i},${e}`:!c&&l?`M ${i},${e} L ${n},${r}`:`M ${i},${e} L ${i},${r}`;const u=Math.min(15,Math.abs(i-t),Math.abs(r-e)/2),s=Math.min(15,Math.abs(n-i),Math.abs(r-e)/2),o=r>e?u:-u,g=r>e?s:-s,h=n>i?s:-s;return c&&l?`M ${t},${e} L ${i-u},${e} Q ${i},${e} ${i},${e+o} L ${i},${r-g} Q ${i},${r} ${i+h},${r} L ${n},${r}`:c&&!l?`M ${t},${e} L ${i-u},${e} Q ${i},${e} ${i},${e+o} L ${i},${r}`:!c&&l?`M ${i},${e} L ${i},${r-g} Q ${i},${r} ${i+h},${r} L ${n},${r}`:`M ${i},${e} L ${i},${r}`},yt=t.useCallback(()=>{if(!ht.current&&!_.current){ht.current=!0;try{if(!r.current)return;const t=t=>{const e=t.split("-"),n=e[0];if(!m[n]&&!1===C)return!1;if(C&&!m[`left-${n}`]&&!m[`right-${n}`]&&!m[n])return!1;let r=n;for(let t=1;t<e.length-1;t++)if(r+=`-${e[t]}`,!B[r])return!1;return!0},l=r.current.getBoundingClientRect();gt({width:l.width,height:l.height});const u=[];if(a.forEach(({key:t})=>{const e=d.current[t]?.current,n=f.current[t]?.current;e&&n&&(e.style.height="auto",n.style.height="auto",e.style.minHeight="0px",n.style.minHeight="0px")}),!_.current){for(let t=0;t<Math.max(g.length,h.length);t++){const e=p.current[t]?.current,n=b.current[t]?.current;e&&(e.style.height="auto",e.style.minHeight="0px"),n&&(n.style.height="auto",n.style.minHeight="0px")}C||Object.keys(A.current).forEach(e=>{if(!t(e))return;const n=A.current[e]?.current,r=y.current[e]?.current;n&&r&&(n.style.height="auto",r.style.height="auto",n.style.minHeight="0px",r.style.minHeight="0px")})}const x={};a.forEach(({key:t})=>{const e=d.current[t]?.current,n=f.current[t]?.current;if(e&&n){const r=e.getBoundingClientRect(),i=n.getBoundingClientRect();x[t]=Math.max(r.height,i.height)}});const L={left:{},right:{}},F={};if(!_.current)if(C){if(T&&null!==I)if("number"==typeof I){const t=I,e=g[t],n=p.current[t]?.current;n&&e&&(e.refIndexes||[]).forEach(e=>{const r=h.findIndex(t=>t.selfIndex===e),i=b.current[r]?.current;if(i&&(m[`left-${t}`]||m[`right-${r}`])){const e=Math.max(n.getBoundingClientRect().height,i.getBoundingClientRect().height);L.left[t]=Math.max(L.left[t]||0,e),L.right[r]=Math.max(L.right[r]||0,e)}})}else{const t=I.split(e.DEVIATION_BADGE_SEPARATOR)[2];if(t){const e=A.current[t]?.current,n=y.current[t]?.current;if(e&&n){const r=Math.max(e.getBoundingClientRect().height,n.getBoundingClientRect().height);F[t]=Math.max(F[t]||0,r)}}}}else{Object.keys(A.current).forEach(e=>{if(!t(e))return;const n=A.current[e]?.current,r=y.current[e]?.current;if(n&&r&&null!==n.offsetParent&&null!==r.offsetParent){const t=n.getBoundingClientRect(),i=r.getBoundingClientRect(),c=Math.max(t.height,i.height);F[e]=c,n.style.minHeight=`${c}px`,r.style.minHeight=`${c}px`}});for(let t=0;t<Math.min(g.length,h.length);t++){const e=p.current[t]?.current,n=b.current[t]?.current;if(e&&n){const r=Math.max(e.getBoundingClientRect().height,n.getBoundingClientRect().height);L.left[t]=r,L.right[t]=r}}}if(a.forEach(({key:t})=>{const e=d.current[t]?.current,n=f.current[t]?.current;if(e&&n){const r=x[t];e.style.minHeight=`${r}px`,n.style.minHeight=`${r}px`}}),_.current||(Object.entries(L.left).forEach(([t,e])=>{const n=p.current[Number(t)]?.current;n&&(n.style.minHeight=`${e}px`)}),Object.entries(L.right).forEach(([t,e])=>{const n=b.current[Number(t)]?.current;n&&(n.style.minHeight=`${e}px`)}),C||Object.keys(F).forEach(t=>{const e=A.current[t]?.current,n=y.current[t]?.current;if(e&&n&&F[t]){const r=F[t];e.style.minHeight=`${r}px`,n.style.minHeight=`${r}px`}})),!E){const t=(t,e)=>{if(!C)return h[e]?[e]:[];const n=(t.refIndexes||[]).map(t=>h.findIndex(e=>e.selfIndex===t)).filter(t=>-1!==t);return!n.length&&h[e]?[e]:Array.from(new Set(n))};g.forEach((e,n)=>{const r=e.continuationSourceRowId?g.findIndex(t=>t.comparisonRowId===e.continuationSourceRowId):-1,s=r>=0?r:n,o=p.current[s]?.current;if(!o)return;t(e,n).forEach(t=>{const e=b.current[t]?.current;if(!e)return;const a=o.getBoundingClientRect(),d=e.getBoundingClientRect(),f=a.right-l.left,p=d.left-l.left;let A=a.top+18-l.top,y=d.top+18-l.top;if(C&&T&&I===n){const t=i.current?.getBoundingClientRect().top??0,e=c.current?.getBoundingClientRect().top??0,n=t+(i.current?.clientHeight??1/0),r=e+(c.current?.clientHeight??1/0),u=(t,e,n)=>Math.max(e,Math.min(n,t));A=u(a.top+18,t,n)-l.top,y=u(d.top+18,e,r)-l.top}const $=v(s);$&&u.push({id:`line-${s}-${t}`,x1:f,y1:A,x2:p,y2:y,style:$,sectionIdx:s,targetRightIdx:t,isSubSection:!1,isMappingContinuation:r>=0,hasCognitive:!!(g[s]?.cognitiveData||h[t]?.cognitiveData||g[s]?.nodeId&&M[g[s].nodeId])})})})}if(!E&&T&&"string"==typeof I&&I.includes(e.DEVIATION_BADGE_SEPARATOR)){const[t,n,r,s]=I.split(e.DEVIATION_BADGE_SEPARATOR),o=`${t}${e.DEVIATION_BADGE_SEPARATOR}${n}`,g=$.current[o]?.current,h=R.current[o]?.current;if(g&&h){const e=g.getBoundingClientRect(),s=h.getBoundingClientRect(),a=e.right-l.left,d=s.left-l.left;let f=e.top+e.height/2-l.top,p=s.top+s.height/2-l.top;if(C){const t=i.current?.getBoundingClientRect().top??0,n=c.current?.getBoundingClientRect().top??0,r=t+(i.current?.clientHeight??1/0),u=n+(c.current?.clientHeight??1/0),o=(t,e,n)=>Math.max(e,Math.min(n,t));f=o(e.top+e.height/2,t,r)-l.top,p=o(s.top+s.height/2,n,u)-l.top}const b=O(t,n)??D(r);b&&u.push({id:`line-subsec-${o}`,x1:a,y1:f,x2:d,y2:p,style:b,sectionIdx:Number(r.split("-")[0]),isSubSection:!0,subSectionKeyPath:I})}}if(nt(u),s.current&&o.current){const t=s.current.getBoundingClientRect(),e=o.current.getBoundingClientRect(),n=(t.top+t.height/2-l.top+e.top+e.height/2-l.top)/2;it({x1:t.right-l.left,x2:e.left-l.left,y:n})}else it(null);if(S.size>0){const t=[],r=i.current,u=c.current;if(r&&u){const i=[],c=r.getBoundingClientRect().top,s=u.getBoundingClientRect().top,o=c+r.clientHeight,a=s+u.clientHeight,d=r.scrollTop,f=u.scrollTop,p=l.top,b=(t,e,n)=>Math.max(e,Math.min(n,t));S.forEach(r=>{if(E){let g=null,h=null,A=null;if("string"==typeof r&&r.includes(e.DEVIATION_BADGE_SEPARATOR)){const[t,n,i]=r.split(e.DEVIATION_BADGE_SEPARATOR),c=`${t}${e.DEVIATION_BADGE_SEPARATOR}${n}`;g=$.current[c]?.current,A=O(t,n)??D(i),h=Number(i?.split("-")[0]||0)}else h=Number(r),g=$.current[h]?.current,A=v(h);if(!g)return;const y=n.getVisibleGuidelineTargets(u);y.forEach((n,u)=>{const h=g.getBoundingClientRect(),$=n.getBoundingClientRect(),R=h.right-l.left,x=$.left-l.left-0,m=R+75,B=h.top+h.height/2,S=$.top+$.height/2,T=B-c+d,I=S-s+f,C=`conn-guide-${r}-${u}`;let E="";if("string"==typeof r&&r.includes(e.DEVIATION_BADGE_SEPARATOR)){E=(r.split(e.DEVIATION_BADGE_SEPARATOR)[2]||"").split("-").map(t=>Number(t)+1).join(".")}else E=String(Number(r)+1);const M=String.fromCharCode(97+u),v=1===y.length?null:`${E}(${M})`;i.push({lhsScrollY:T,rhsScrollY:I,x1:R,x2:x,containerTop:p,leftIdx:r,rhsArrayIdx:u,styleColor:A?.badgeBorder||"#6366F1",styleBg:A?.badgeBg||"#FFFFFF",styleText:A?.badgeText||"#A16207",styleId:C,centerX:m});const D=b(B,c,o),O=b(S,s,a),L=D-p,_=O-p,F=At(R,L,x,_,m,B>=c-4&&B<=o+4,S>=s-4&&S<=a+4);t.push({id:C,pathD:F,style:A,leftIdx:r,rhsArrayIdx:u,x1:R,x2:x,y1:L,y2:_,centerX:m,matchLabel:v,isGuideline:!0})})}else if("string"==typeof r&&r.includes(e.DEVIATION_BADGE_SEPARATOR)){const[n,u,g,h]=r.split(e.DEVIATION_BADGE_SEPARATOR),A=`${n}${e.DEVIATION_BADGE_SEPARATOR}${u}`,y=$.current[A]?.current,x=R.current[A]?.current;if(!y||!x)return;const m=y.getBoundingClientRect(),B=x.getBoundingClientRect(),S=O(n,u)??D(g),T=m.right-l.left,I=B.left-l.left-0,C=T+75,E=m.top+m.height/2,M=B.top+B.height/2,v=E-c+d,L=M-s+f,_=`conn-subsec-${A}`,F=((g||"").split("-").map(t=>Number(t)+1).join("."),null);i.push({lhsScrollY:v,rhsScrollY:L,x1:T,x2:I,containerTop:p,leftIdx:r,rhsArrayIdx:r,styleColor:S?.badgeBorder||"#6366F1",styleBg:S?.badgeBg||"#FFFFFF",styleText:S?.badgeText||"#A16207",styleId:_,centerX:C});const N=b(E,c,o),H=b(M,s,a),P=N-p,k=H-p,w=At(T,P,I,k,C,E>=c-4&&E<=o+4,M>=s-4&&M<=a+4);t.push({id:_,pathD:w,style:S,leftIdx:r,rhsArrayIdx:r,x1:T,x2:I,y1:P,y2:k,matchLabel:F})}else if(C){const e=r,n=g[e];if(!n?.refIndexes?.length)return;n.refIndexes.forEach((u,g)=>{const A=h.findIndex(t=>t.selfIndex===u);if(-1===A)return;const y=$.current[e]?.current,x=R.current[A]?.current;if(!y||!x)return;const m=y.getBoundingClientRect(),B=x.getBoundingClientRect(),S=v(e),T=m.right-l.left,I=B.left-l.left-0,C=T+75,E=m.top+m.height/2,M=B.top+B.height/2,D=E-c+d,O=M-s+f,L=`conn-${e}-${A}`,_=String(Number(r)+1),F=String.fromCharCode(97+g),N=1===n.refIndexes.length?null:`${_}(${F})`;i.push({lhsScrollY:D,rhsScrollY:O,x1:T,x2:I,containerTop:p,leftIdx:e,rhsArrayIdx:A,styleColor:S?.badgeBorder||"#6366F1",styleBg:S?.badgeBg||"#FFFFFF",styleText:S?.badgeText||"#A16207",styleId:L,centerX:C});const H=b(E,c,o),P=b(M,s,a),k=H-p,w=P-p,G=At(T,k,I,w,C,E>=c-4&&E<=o+4,M>=s-4&&M<=a+4);t.push({id:L,pathD:G,style:S,leftIdx:e,rhsArrayIdx:A,x1:T,x2:I,y1:k,y2:w,matchLabel:N})})}else{const e=r,n=e,u=$.current[e]?.current,g=R.current[n]?.current;if(!u||!g)return;const h=u.getBoundingClientRect(),A=g.getBoundingClientRect(),y=v(e),x=h.right-l.left,m=A.left-l.left-0,B=x+75,S=h.top+h.height/2,T=A.top+A.height/2,I=S-c+d,C=T-s+f,E=`conn-${e}-${n}`,M=(String(Number(r)+1),null);i.push({lhsScrollY:I,rhsScrollY:C,x1:x,x2:m,containerTop:p,leftIdx:e,rhsArrayIdx:n,styleColor:y?.badgeBorder||"#6366F1",styleBg:y?.badgeBg||"#FFFFFF",styleText:y?.badgeText||"#A16207",styleId:E,centerX:B});const D=b(S,c,o),O=b(T,s,a),L=D-p,_=O-p,F=At(x,L,m,_,B,S>=c-4&&S<=o+4,T>=s-4&&T<=a+4);t.push({id:E,pathD:F,style:y,leftIdx:e,rhsArrayIdx:n,x1:x,x2:m,y1:L,y2:_,matchLabel:M})}}),bt.current=i}st(t),setTimeout(()=>$t(),10)}else st([]),bt.current=[],setTimeout(()=>$t(),10)}catch(t){console.error("Line render safe fail: ",t)}finally{ht.current=!1}}},[a,g,h,M,Z,tt,v,O,C,T,I,S,m,B,E]),$t=t.useCallback(()=>{const t=bt.current;if(!t.length)return u.current["guideline-up-stroke"]?.setAttribute("visibility","hidden"),u.current["guideline-up-badge"]?.setAttribute("visibility","hidden"),u.current["guideline-down-stroke"]?.setAttribute("visibility","hidden"),void u.current["guideline-down-badge"]?.setAttribute("visibility","hidden");if(_.current)return;const e=i.current?.scrollTop??0,n=c.current?.scrollTop??0,l=i.current?.clientHeight??1/0,s=c.current?.clientHeight??1/0,o=i.current?.getBoundingClientRect().top??0,g=c.current?.getBoundingClientRect().top??0,h=o+l,a=g+s,d=r.current?.getBoundingClientRect(),f=d?.top??0,p=d?.height??1/0,b=(t,e,n)=>Math.max(e,Math.min(n,t));let A=0,y=0,$=0,R=0,x="#6366F1",m="#A16207",B=!1,S=0;if(t.forEach(t=>{const r=t.lhsScrollY-e+o,i=t.rhsScrollY-n+g,c=u.current[t.styleId+"-stroke"],l=u.current[t.styleId+"-bg"],s=u.current[t.styleId+"-btn"],d=u.current[t.styleId+"-number"];if(!c&&!l)return;const p=b(r,o,h),T=b(i,g,a),I=p-f,C=T-f,E=r>=o-4&&r<=h+4,M=i>=g-4&&i<=a+4;let v=!0;B=!0;const D=t.centerX||t.x1+75;0===$&&($=t.x1,R=I,S=D,x=t.styleColor,t.styleBg,m=t.styleText||"#A16207"),i<g-4?(A++,v=!1):i>a+4&&(y++,v=!1);const O=At(t.x1,I,t.x2,C,S,E,M);c&&(v&&O?(c.setAttribute("visibility","visible"),c.setAttribute("d",O)):c.setAttribute("visibility","hidden")),l&&(v&&O?(l.setAttribute("visibility","visible"),l.setAttribute("d",O)):l.setAttribute("visibility","hidden")),s&&(E&&v?(s.setAttribute("visibility","visible"),s.setAttribute("y",String(I-12))):s.setAttribute("visibility","hidden")),d&&(E&&v?(d.setAttribute("visibility","visible"),d.setAttribute("transform",`translate(${t.x2-42}, ${C})`)):d.setAttribute("visibility","hidden"))}),B&&S>0){const t=u.current["guideline-up-stroke"],e=u.current["guideline-up-badge"],n=u.current["guideline-up-arrow"],r=u.current["guideline-up-text"],i=u.current["guideline-up-badge-rect"];if(A>0){const c=Math.max(15,g-f+15),l=Math.min(15,Math.abs(S-$),Math.max(0,R-c)),u=`M ${$},${R} L ${S-l},${R} Q ${S},${R} ${S},${R-l} L ${S},${c}`;t?.setAttribute("visibility","visible"),t?.setAttribute("d",u),t?.setAttribute("stroke",x),e?.setAttribute("visibility","visible"),e?.setAttribute("transform",`translate(${S}, ${c})`),n&&n.setAttribute("fill",x),r&&(r.textContent=`+${A}`,r.setAttribute("fill",m)),i&&i.setAttribute("stroke",x)}else t?.setAttribute("visibility","hidden"),e?.setAttribute("visibility","hidden");const c=u.current["guideline-down-stroke"],l=u.current["guideline-down-badge"],s=u.current["guideline-down-arrow"],o=u.current["guideline-down-text"],h=u.current["guideline-down-badge-rect"];if(y>0){const t=Math.min(p-15,a-f-15),e=Math.min(15,Math.abs(S-$),Math.max(0,t-R)),n=`M ${$},${R} L ${S-e},${R} Q ${S},${R} ${S},${R+e} L ${S},${t}`;c?.setAttribute("visibility","visible"),c?.setAttribute("d",n),c?.setAttribute("stroke",x),l?.setAttribute("visibility","visible"),l?.setAttribute("transform",`translate(${S}, ${t})`),s&&s.setAttribute("fill",x),o&&(o.textContent=`+${y}`,o.setAttribute("fill",m)),h&&h.setAttribute("stroke",x)}else c?.setAttribute("visibility","hidden"),l?.setAttribute("visibility","hidden")}},[]),Rt=t.useCallback(()=>{bt.current.length>0&&!_.current||(null!==ft.current&&clearTimeout(ft.current),ft.current=setTimeout(()=>{Y.current(),ft.current=null},50))},[]),xt=t.useCallback(t=>{if(null!==U.current&&W.current&&Math.abs(t.currentTarget.scrollTop-U.current)<=2){const t=W.current;U.current=null,W.current=null,t()}if(!dt.current&&!z.current){if(C&&Q&&(F.current||S.size>0)){const n=t.currentTarget,r=i.current,l=c.current,u=n===r?l:n===l?r:null;if(n&&u){const t=()=>{const t=P.current,n=k.current;if(null===t)return{leftAnchor:null,rightAnchor:null};if("string"==typeof t&&t.includes(e.DEVIATION_BADGE_SEPARATOR)){const n=t.split(e.DEVIATION_BADGE_SEPARATOR),r=`${n[0]}${e.DEVIATION_BADGE_SEPARATOR}${n[1]}`;return{leftAnchor:$.current[r]?.current||A.current[n[2]]?.current||p.current[Number(n[2])]?.current||null,rightAnchor:R.current[r]?.current||y.current[n[3]]?.current||b.current[Number(n[3])]?.current||null}}const r=Number(t),i=null!==n?Number(n):r;return{leftAnchor:$.current[r]?.current||x.current[r]?.current||p.current[r]?.current||null,rightAnchor:R.current[i]?.current||b.current[i]?.current||null}},{leftAnchor:i,rightAnchor:c}=t(),l=n===r?i:c,s=n===r?c:i;let o=null;if(l&&s){const t=l.getBoundingClientRect(),e=s.getBoundingClientRect(),n=u.getBoundingClientRect(),r=t.top+t.height/2;o=e.top-n.top+u.scrollTop+e.height/2-(r-n.top)}else{const t=Math.max(0,n.scrollHeight-n.clientHeight),e=Math.max(0,u.scrollHeight-u.clientHeight);o=t>0?n.scrollTop/t*e:n.scrollTop}const g=Math.max(0,u.scrollHeight-u.clientHeight);o=Math.max(0,Math.min(o,g)),Math.abs(u.scrollTop-o)>1&&(dt.current=!0,u.scrollTop=o,requestAnimationFrame(()=>{dt.current=!1}))}}C||Rt(),at.current||(at.current=!0,requestAnimationFrame(()=>{if(F.current){const t=i.current,n=c.current;if(t&&n&&H.current){if(!N.current){const n=P.current;let i;if("string"==typeof n&&n.includes(e.DEVIATION_BADGE_SEPARATOR)){const t=n.split(e.DEVIATION_BADGE_SEPARATOR),r=`${t[0]}${e.DEVIATION_BADGE_SEPARATOR}${t[1]}`;i=$.current[r]?.current}else i=$.current[n]?.current;if(i){const e=i.getBoundingClientRect();N.current={badgeScreenY:e.top+e.height/2,initialScrollTop:t.scrollTop,leftTop:t.getBoundingClientRect().top,leftBottom:t.getBoundingClientRect().top+t.clientHeight,cTop:r.current?.getBoundingClientRect().top??0}}}if(N.current){const e=N.current,n=t.scrollTop-e.initialScrollTop,r=e.badgeScreenY-n,i=(((t,e,n)=>Math.max(e,Math.min(n,t)))(r,e.leftTop,e.leftBottom)-e.cTop).toString(),c=r>=e.leftTop-4&&r<=e.leftBottom+4;H.current.setAttribute("y1",i),H.current.setAttribute("y2",i),H.current.setAttribute("visibility",c?"visible":"hidden")}}}$t(),at.current=!1}))}},[$t,C,Q,S,Rt]);return t.useEffect(()=>{Y.current=yt},[yt]),t.useEffect(()=>{const t=setTimeout(Rt,250),e=()=>X.current();return window.addEventListener("resize",e),()=>{clearTimeout(t),null!==ft.current&&clearTimeout(ft.current),null!==j.current&&clearTimeout(j.current),window.removeEventListener("resize",e)}},[q,K,J,a,m,B,g,h,Z,Rt,T,I,L,S]),{lines:et,setLines:nt,overallConnector:rt,setOverallConnector:it,connectedLines:ut,setConnectedLines:st,svgDimensions:ot,cachedConnectedPositions:bt,calculateLines:yt,calculateLinesRef:Y,calculateLinesDebounced:Rt,handleColumnScroll:xt}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("../CognitiveComparehelpers.js");exports.useLinesCalculator=({containerRef:n,leftContainerRef:r,rightContainerRef:i,svgContainerRef:c,pathRefs:l,leftHeaderRef:u,rightHeaderRef:s,proposedSections:o,existingSections:h,visibleFields:g,leftRefs:a,rightRefs:d,sectionLeftRefs:f,sectionRightRefs:p,subSectionLeftRefs:b,subSectionRightRefs:A,lhsBadgeRefs:y,rhsBadgeRefs:$,sectionRowRefs:R,expandedSections:x,expandedSubSections:m,connectedSections:B,isSideBySide:S,activeSideBySideSection:I,maintainRelativeOrder:T,isGuidelineMode:C,cognitiveMap:E,getSectionCompareStyle:M,getSubSectionCompareStyle:v,getDeviationStyleByKey:D,isArrowVisible:O,isAnimatingRef:L,isSideBySideRef:_,sideBySideCacheRef:F,sideBySideLineRef:N,activeSideBySideSectionRef:H,activeSideBySideRightSectionRef:P,connectedLines:k,setConnectedLines:w,cachedConnectedPositions:G,calculateLinesRef:V,resizeTimerRef:Y,scrollLock:j,scrollSyncLocked:z,handleResizeRef:Q,activeProposed:X,existingRule:q,analysisData:K,pendingScrollTargetRef:J,pendingScrollCallbackRef:U,resolvedComparisonConfig:W,getFieldData:Z})=>{const[tt,et]=t.useState([]),[nt,rt]=t.useState(null),[it,ct]=t.useState([]),lt=k??it,ut=w??ct,[st,ot]=t.useState({width:0,height:0}),ht=t.useRef(!1),gt=t.useRef(!1),at=t.useRef(!1),dt=t.useRef(null),ft=t.useRef([]),pt=G??ft,bt=(t,e,n,r,i,c,l)=>{if(Math.abs(r-e)<=1)return c&&l?`M ${t},${e} L ${n},${r}`:c&&!l?`M ${t},${e} L ${i},${e}`:!c&&l?`M ${i},${e} L ${n},${r}`:`M ${i},${e} L ${i},${r}`;const u=Math.min(15,Math.abs(i-t),Math.abs(r-e)/2),s=Math.min(15,Math.abs(n-i),Math.abs(r-e)/2),o=r>e?u:-u,h=r>e?s:-s,g=n>i?s:-s;return c&&l?`M ${t},${e} L ${i-u},${e} Q ${i},${e} ${i},${e+o} L ${i},${r-h} Q ${i},${r} ${i+g},${r} L ${n},${r}`:c&&!l?`M ${t},${e} L ${i-u},${e} Q ${i},${e} ${i},${e+o} L ${i},${r}`:!c&&l?`M ${i},${e} L ${i},${r-h} Q ${i},${r} ${i+g},${r} L ${n},${r}`:`M ${i},${e} L ${i},${r}`},At=t.useCallback(()=>{if(!ht.current&&!L.current){ht.current=!0;try{if(!n.current)return;const t=t=>{const e=t.split("-"),n=e[0];if(!x[n]&&!1===T)return!1;if(T&&!x[`left-${n}`]&&!x[`right-${n}`]&&!x[n])return!1;let r=n;for(let t=1;t<e.length-1;t++)if(r+=`-${e[t]}`,!m[r])return!1;return!0},c=n.current.getBoundingClientRect();ot({width:c.width,height:c.height});const l=[];if(g.forEach(({key:t})=>{const e=a.current[t]?.current,n=d.current[t]?.current;e&&n&&(e.style.height="auto",n.style.height="auto",e.style.minHeight="0px",n.style.minHeight="0px")}),!L.current){for(let t=0;t<Math.max(o.length,h.length);t++){const e=f.current[t]?.current,n=p.current[t]?.current;e&&(e.style.height="auto",e.style.minHeight="0px"),n&&(n.style.height="auto",n.style.minHeight="0px")}T||Object.keys(b.current).forEach(e=>{if(!t(e))return;const n=b.current[e]?.current,r=A.current[e]?.current;n&&r&&(n.style.height="auto",r.style.height="auto",n.style.minHeight="0px",r.style.minHeight="0px")})}const R={};g.forEach(({key:t})=>{const e=a.current[t]?.current,n=d.current[t]?.current;if(e&&n){const r=e.getBoundingClientRect(),i=n.getBoundingClientRect();R[t]=Math.max(r.height,i.height)}});const O={left:{},right:{}},_={};if(!L.current)if(T){if(S&&null!==I)if("number"==typeof I){const t=I,e=o[t],n=f.current[t]?.current;n&&e&&(e.refIndexes||[]).forEach(e=>{const r=h.findIndex(t=>t.selfIndex===e),i=p.current[r]?.current;if(i&&(x[`left-${t}`]||x[`right-${r}`])){const e=Math.max(n.getBoundingClientRect().height,i.getBoundingClientRect().height);O.left[t]=Math.max(O.left[t]||0,e),O.right[r]=Math.max(O.right[r]||0,e)}})}else{const t=I.split(e.DEVIATION_BADGE_SEPARATOR)[2];if(t){const e=b.current[t]?.current,n=A.current[t]?.current;if(e&&n){const r=Math.max(e.getBoundingClientRect().height,n.getBoundingClientRect().height);_[t]=Math.max(_[t]||0,r)}}}}else{Object.keys(b.current).forEach(e=>{if(!t(e))return;const n=b.current[e]?.current,r=A.current[e]?.current;if(n&&r&&null!==n.offsetParent&&null!==r.offsetParent){const t=n.getBoundingClientRect(),i=r.getBoundingClientRect(),c=Math.max(t.height,i.height);_[e]=c,n.style.minHeight=`${c}px`,r.style.minHeight=`${c}px`}});for(let t=0;t<Math.min(o.length,h.length);t++){const e=f.current[t]?.current,n=p.current[t]?.current;if(e&&n){const r=Math.max(e.getBoundingClientRect().height,n.getBoundingClientRect().height);O.left[t]=r,O.right[t]=r}}}if(g.forEach(({key:t})=>{const e=a.current[t]?.current,n=d.current[t]?.current;if(e&&n){const r=R[t];e.style.minHeight=`${r}px`,n.style.minHeight=`${r}px`}}),L.current||(Object.entries(O.left).forEach(([t,e])=>{const n=f.current[Number(t)]?.current;n&&(n.style.minHeight=`${e}px`)}),Object.entries(O.right).forEach(([t,e])=>{const n=p.current[Number(t)]?.current;n&&(n.style.minHeight=`${e}px`)}),T||Object.keys(_).forEach(t=>{const e=b.current[t]?.current,n=A.current[t]?.current;if(e&&n&&_[t]){const r=_[t];e.style.minHeight=`${r}px`,n.style.minHeight=`${r}px`}})),!C){const t=(t,e)=>{if(!T)return h[e]?[e]:[];const n=(t.refIndexes||[]).map(t=>h.findIndex(e=>e.selfIndex===t)).filter(t=>-1!==t);return!n.length&&h[e]?[e]:Array.from(new Set(n))};o.forEach((e,n)=>{const u=e.continuationSourceRowId?o.findIndex(t=>t.comparisonRowId===e.continuationSourceRowId):-1,s=u>=0?u:n,g=f.current[s]?.current;if(!g)return;t(e,n).forEach(t=>{const e=p.current[t]?.current;if(!e)return;const a=g.getBoundingClientRect(),d=e.getBoundingClientRect(),f=a.right-c.left,b=d.left-c.left;let A=a.top+18-c.top,y=d.top+18-c.top;if(T&&S&&I===n){const t=r.current?.getBoundingClientRect().top??0,e=i.current?.getBoundingClientRect().top??0,n=t+(r.current?.clientHeight??1/0),l=e+(i.current?.clientHeight??1/0),u=(t,e,n)=>Math.max(e,Math.min(n,t));A=u(a.top+18,t,n)-c.top,y=u(d.top+18,e,l)-c.top}const $=M(s);$&&l.push({id:`line-${s}-${t}`,x1:f,y1:A,x2:b,y2:y,style:$,sectionIdx:s,targetRightIdx:t,isSubSection:!1,isMappingContinuation:u>=0,hasCognitive:!!(o[s]?.cognitiveData||h[t]?.cognitiveData||o[s]?.nodeId&&E[o[s].nodeId])})})})}if(!C&&S&&"string"==typeof I&&I.includes(e.DEVIATION_BADGE_SEPARATOR)){const[t,n,u,s]=I.split(e.DEVIATION_BADGE_SEPARATOR),o=`${t}${e.DEVIATION_BADGE_SEPARATOR}${n}`,h=y.current[o]?.current,g=$.current[o]?.current;if(h&&g){const e=h.getBoundingClientRect(),s=g.getBoundingClientRect(),a=e.right-c.left,d=s.left-c.left;let f=e.top+e.height/2-c.top,p=s.top+s.height/2-c.top;if(T){const t=r.current?.getBoundingClientRect().top??0,n=i.current?.getBoundingClientRect().top??0,l=t+(r.current?.clientHeight??1/0),u=n+(i.current?.clientHeight??1/0),o=(t,e,n)=>Math.max(e,Math.min(n,t));f=o(e.top+e.height/2,t,l)-c.top,p=o(s.top+s.height/2,n,u)-c.top}const b=D(t,n)??v(u);b&&l.push({id:`line-subsec-${o}`,x1:a,y1:f,x2:d,y2:p,style:b,sectionIdx:Number(u.split("-")[0]),isSubSection:!0,subSectionKeyPath:I})}}if(et(l),u.current&&s.current){const t=u.current.getBoundingClientRect(),e=s.current.getBoundingClientRect(),n=(t.top+t.height/2-c.top+e.top+e.height/2-c.top)/2;rt({x1:t.right-c.left,x2:e.left-c.left,y:n})}else rt(null);if(B.size>0){const t=[],n=r.current,l=i.current;if(n&&l){const r=[],i=n.getBoundingClientRect().top,u=l.getBoundingClientRect().top,s=i+n.clientHeight,g=u+l.clientHeight,a=n.scrollTop,d=l.scrollTop,f=c.top,p=(t,e,n)=>Math.max(e,Math.min(n,t));B.forEach(n=>{if(C){let l=null,o=null,h=null;if("string"==typeof n&&n.includes(e.DEVIATION_BADGE_SEPARATOR)){const[t,r,i]=n.split(e.DEVIATION_BADGE_SEPARATOR),c=`${t}${e.DEVIATION_BADGE_SEPARATOR}${r}`;l=y.current[c]?.current,h=D(t,r)??v(i),o=Number(i?.split("-")[0]||0)}else o=Number(n),l=y.current[o]?.current,h=M(o);if(!l)return;const b=document.querySelectorAll('[id^="guideline-target-"]');b.forEach((o,A)=>{const y=l.getBoundingClientRect(),$=o.getBoundingClientRect(),R=y.right-c.left,x=$.left-c.left-0,m=R+75,B=y.top+y.height/2,S=$.top+$.height/2,I=B-i+a,T=S-u+d,C=`conn-guide-${n}-${A}`;let E="";if("string"==typeof n&&n.includes(e.DEVIATION_BADGE_SEPARATOR)){E=(n.split(e.DEVIATION_BADGE_SEPARATOR)[2]||"").split("-").map(t=>Number(t)+1).join(".")}else E=String(Number(n)+1);const M=String.fromCharCode(97+A),v=1===b.length?null:`${E}(${M})`;r.push({lhsScrollY:I,rhsScrollY:T,x1:R,x2:x,containerTop:f,leftIdx:n,rhsArrayIdx:A,styleColor:h?.badgeBorder||"#6366F1",styleBg:h?.badgeBg||"#FFFFFF",styleText:h?.badgeText||"#A16207",styleId:C,centerX:m});const D=p(B,i,s),O=p(S,u,g),L=D-f,_=O-f,F=bt(R,L,x,_,m,B>=i-4&&B<=s+4,S>=u-4&&S<=g+4);t.push({id:C,pathD:F,style:h,leftIdx:n,rhsArrayIdx:A,x1:R,x2:x,y1:L,y2:_,centerX:m,matchLabel:v,isGuideline:!0})})}else if("string"==typeof n&&n.includes(e.DEVIATION_BADGE_SEPARATOR)){const[l,o,h,b]=n.split(e.DEVIATION_BADGE_SEPARATOR),A=`${l}${e.DEVIATION_BADGE_SEPARATOR}${o}`,R=y.current[A]?.current,x=$.current[A]?.current;if(!R||!x)return;const m=R.getBoundingClientRect(),B=x.getBoundingClientRect(),S=D(l,o)??v(h),I=m.right-c.left,T=B.left-c.left-0,C=I+75,E=m.top+m.height/2,M=B.top+B.height/2,O=E-i+a,L=M-u+d,_=`conn-subsec-${A}`,F=((h||"").split("-").map(t=>Number(t)+1).join("."),null);r.push({lhsScrollY:O,rhsScrollY:L,x1:I,x2:T,containerTop:f,leftIdx:n,rhsArrayIdx:n,styleColor:S?.badgeBorder||"#6366F1",styleBg:S?.badgeBg||"#FFFFFF",styleText:S?.badgeText||"#A16207",styleId:_,centerX:C});const N=p(E,i,s),H=p(M,u,g),P=N-f,k=H-f,w=bt(I,P,T,k,C,E>=i-4&&E<=s+4,M>=u-4&&M<=g+4);t.push({id:_,pathD:w,style:S,leftIdx:n,rhsArrayIdx:n,x1:I,x2:T,y1:P,y2:k,matchLabel:F})}else if(T){const e=n,l=o[e];if(!l?.refIndexes?.length)return;l.refIndexes.forEach((o,b)=>{const A=h.findIndex(t=>t.selfIndex===o);if(-1===A)return;const R=y.current[e]?.current,x=$.current[A]?.current;if(!R||!x)return;const m=R.getBoundingClientRect(),B=x.getBoundingClientRect(),S=M(e),I=m.right-c.left,T=B.left-c.left-0,C=I+75,E=m.top+m.height/2,v=B.top+B.height/2,D=E-i+a,O=v-u+d,L=`conn-${e}-${A}`,_=String(Number(n)+1),F=String.fromCharCode(97+b),N=1===l.refIndexes.length?null:`${_}(${F})`;r.push({lhsScrollY:D,rhsScrollY:O,x1:I,x2:T,containerTop:f,leftIdx:e,rhsArrayIdx:A,styleColor:S?.badgeBorder||"#6366F1",styleBg:S?.badgeBg||"#FFFFFF",styleText:S?.badgeText||"#A16207",styleId:L,centerX:C});const H=p(E,i,s),P=p(v,u,g),k=H-f,w=P-f,G=bt(I,k,T,w,C,E>=i-4&&E<=s+4,v>=u-4&&v<=g+4);t.push({id:L,pathD:G,style:S,leftIdx:e,rhsArrayIdx:A,x1:I,x2:T,y1:k,y2:w,matchLabel:N})})}else{const e=n,l=e,o=y.current[e]?.current,h=$.current[l]?.current;if(!o||!h)return;const b=o.getBoundingClientRect(),A=h.getBoundingClientRect(),R=M(e),x=b.right-c.left,m=A.left-c.left-0,B=x+75,S=b.top+b.height/2,I=A.top+A.height/2,T=S-i+a,C=I-u+d,E=`conn-${e}-${l}`,v=(String(Number(n)+1),null);r.push({lhsScrollY:T,rhsScrollY:C,x1:x,x2:m,containerTop:f,leftIdx:e,rhsArrayIdx:l,styleColor:R?.badgeBorder||"#6366F1",styleBg:R?.badgeBg||"#FFFFFF",styleText:R?.badgeText||"#A16207",styleId:E,centerX:B});const D=p(S,i,s),O=p(I,u,g),L=D-f,_=O-f,F=bt(x,L,m,_,B,S>=i-4&&S<=s+4,I>=u-4&&I<=g+4);t.push({id:E,pathD:F,style:R,leftIdx:e,rhsArrayIdx:l,x1:x,x2:m,y1:L,y2:_,matchLabel:v})}}),pt.current=r}ut(t),setTimeout(()=>yt(),10)}else ut([]),pt.current=[],setTimeout(()=>yt(),10)}catch(t){console.error("Line render safe fail: ",t)}finally{ht.current=!1}}},[g,o,h,E,W,Z,M,D,T,S,I,B,x,m,C]),yt=t.useCallback(()=>{const t=pt.current;if(!t.length)return l.current["guideline-up-stroke"]?.setAttribute("visibility","hidden"),l.current["guideline-up-badge"]?.setAttribute("visibility","hidden"),l.current["guideline-down-stroke"]?.setAttribute("visibility","hidden"),void l.current["guideline-down-badge"]?.setAttribute("visibility","hidden");if(L.current)return;const e=r.current?.scrollTop??0,c=i.current?.scrollTop??0,u=r.current?.clientHeight??1/0,s=i.current?.clientHeight??1/0,o=r.current?.getBoundingClientRect().top??0,h=i.current?.getBoundingClientRect().top??0,g=o+u,a=h+s,d=n.current?.getBoundingClientRect(),f=d?.top??0,p=d?.height??1/0,b=(t,e,n)=>Math.max(e,Math.min(n,t));let A=0,y=0,$=0,R=0,x="#6366F1",m="#A16207",B=!1,S=0;if(t.forEach(t=>{const n=t.lhsScrollY-e+o,r=t.rhsScrollY-c+h,i=l.current[t.styleId+"-stroke"],u=l.current[t.styleId+"-bg"],s=l.current[t.styleId+"-btn"],d=l.current[t.styleId+"-number"];if(!i&&!u)return;const p=b(n,o,g),I=b(r,h,a),T=p-f,C=I-f,E=n>=o-4&&n<=g+4,M=r>=h-4&&r<=a+4;let v=!0;B=!0;const D=t.centerX||t.x1+75;0===$&&($=t.x1,R=T,S=D,x=t.styleColor,t.styleBg,m=t.styleText||"#A16207"),r<h-4?(A++,v=!1):r>a+4&&(y++,v=!1);const O=bt(t.x1,T,t.x2,C,S,E,M);i&&(v&&O?(i.setAttribute("visibility","visible"),i.setAttribute("d",O)):i.setAttribute("visibility","hidden")),u&&(v&&O?(u.setAttribute("visibility","visible"),u.setAttribute("d",O)):u.setAttribute("visibility","hidden")),s&&(E&&v?(s.setAttribute("visibility","visible"),s.setAttribute("y",String(T-12))):s.setAttribute("visibility","hidden")),d&&(E&&v?(d.setAttribute("visibility","visible"),d.setAttribute("transform",`translate(${t.x2-42}, ${C})`)):d.setAttribute("visibility","hidden"))}),B&&S>0){const t=l.current["guideline-up-stroke"],e=l.current["guideline-up-badge"],n=l.current["guideline-up-arrow"],r=l.current["guideline-up-text"],i=l.current["guideline-up-badge-rect"];if(A>0){const c=Math.max(15,h-f+15),l=Math.min(15,Math.abs(S-$),Math.max(0,R-c)),u=`M ${$},${R} L ${S-l},${R} Q ${S},${R} ${S},${R-l} L ${S},${c}`;t?.setAttribute("visibility","visible"),t?.setAttribute("d",u),t?.setAttribute("stroke",x),e?.setAttribute("visibility","visible"),e?.setAttribute("transform",`translate(${S}, ${c})`),n&&n.setAttribute("fill",x),r&&(r.textContent=`+${A}`,r.setAttribute("fill",m)),i&&i.setAttribute("stroke",x)}else t?.setAttribute("visibility","hidden"),e?.setAttribute("visibility","hidden");const c=l.current["guideline-down-stroke"],u=l.current["guideline-down-badge"],s=l.current["guideline-down-arrow"],o=l.current["guideline-down-text"],g=l.current["guideline-down-badge-rect"];if(y>0){const t=Math.min(p-15,a-f-15),e=Math.min(15,Math.abs(S-$),Math.max(0,t-R)),n=`M ${$},${R} L ${S-e},${R} Q ${S},${R} ${S},${R+e} L ${S},${t}`;c?.setAttribute("visibility","visible"),c?.setAttribute("d",n),c?.setAttribute("stroke",x),u?.setAttribute("visibility","visible"),u?.setAttribute("transform",`translate(${S}, ${t})`),s&&s.setAttribute("fill",x),o&&(o.textContent=`+${y}`,o.setAttribute("fill",m)),g&&g.setAttribute("stroke",x)}else c?.setAttribute("visibility","hidden"),u?.setAttribute("visibility","hidden")}},[]),$t=t.useCallback(()=>{pt.current.length>0&&!L.current||(null!==dt.current&&clearTimeout(dt.current),dt.current=setTimeout(()=>{V.current(),dt.current=null},50))},[]),Rt=t.useCallback(t=>{if(null!==J.current&&U.current&&Math.abs(t.currentTarget.scrollTop-J.current)<=2){const t=U.current;J.current=null,U.current=null,t()}if(!at.current&&!j.current){if(T&&z&&(_.current||B.size>0)){const n=t.currentTarget,c=r.current,l=i.current,u=n===c?l:n===l?c:null;if(n&&u){const t=()=>{const t=H.current,n=P.current;if(null===t)return{leftAnchor:null,rightAnchor:null};if("string"==typeof t&&t.includes(e.DEVIATION_BADGE_SEPARATOR)){const n=t.split(e.DEVIATION_BADGE_SEPARATOR),r=`${n[0]}${e.DEVIATION_BADGE_SEPARATOR}${n[1]}`;return{leftAnchor:y.current[r]?.current||b.current[n[2]]?.current||f.current[Number(n[2])]?.current||null,rightAnchor:$.current[r]?.current||A.current[n[3]]?.current||p.current[Number(n[3])]?.current||null}}const r=Number(t),i=null!==n?Number(n):r;return{leftAnchor:y.current[r]?.current||R.current[r]?.current||f.current[r]?.current||null,rightAnchor:$.current[i]?.current||p.current[i]?.current||null}},{leftAnchor:r,rightAnchor:i}=t(),l=n===c?r:i,s=n===c?i:r;let o=null;if(l&&s){const t=l.getBoundingClientRect(),e=s.getBoundingClientRect(),n=u.getBoundingClientRect(),r=t.top+t.height/2;o=e.top-n.top+u.scrollTop+e.height/2-(r-n.top)}else{const t=Math.max(0,n.scrollHeight-n.clientHeight),e=Math.max(0,u.scrollHeight-u.clientHeight);o=t>0?n.scrollTop/t*e:n.scrollTop}const h=Math.max(0,u.scrollHeight-u.clientHeight);o=Math.max(0,Math.min(o,h)),Math.abs(u.scrollTop-o)>1&&(at.current=!0,u.scrollTop=o,requestAnimationFrame(()=>{at.current=!1}))}}T||$t(),gt.current||(gt.current=!0,requestAnimationFrame(()=>{if(_.current){const t=r.current,c=i.current;if(t&&c&&N.current){if(!F.current){const r=H.current;let i;if("string"==typeof r&&r.includes(e.DEVIATION_BADGE_SEPARATOR)){const t=r.split(e.DEVIATION_BADGE_SEPARATOR),n=`${t[0]}${e.DEVIATION_BADGE_SEPARATOR}${t[1]}`;i=y.current[n]?.current}else i=y.current[r]?.current;if(i){const e=i.getBoundingClientRect();F.current={badgeScreenY:e.top+e.height/2,initialScrollTop:t.scrollTop,leftTop:t.getBoundingClientRect().top,leftBottom:t.getBoundingClientRect().top+t.clientHeight,cTop:n.current?.getBoundingClientRect().top??0}}}if(F.current){const e=F.current,n=t.scrollTop-e.initialScrollTop,r=e.badgeScreenY-n,i=(((t,e,n)=>Math.max(e,Math.min(n,t)))(r,e.leftTop,e.leftBottom)-e.cTop).toString(),c=r>=e.leftTop-4&&r<=e.leftBottom+4;N.current.setAttribute("y1",i),N.current.setAttribute("y2",i),N.current.setAttribute("visibility",c?"visible":"hidden")}}}yt(),gt.current=!1}))}},[yt,T,z,B,$t]);return t.useEffect(()=>{V.current=At},[At]),t.useEffect(()=>{const t=setTimeout($t,250),e=()=>Q.current();return window.addEventListener("resize",e),()=>{clearTimeout(t),null!==dt.current&&clearTimeout(dt.current),null!==Y.current&&clearTimeout(Y.current),window.removeEventListener("resize",e)}},[X,q,K,g,x,m,o,h,W,$t,S,I,O,B]),{lines:tt,setLines:et,overallConnector:nt,setOverallConnector:rt,connectedLines:lt,setConnectedLines:ut,svgDimensions:st,cachedConnectedPositions:pt,calculateLines:At,calculateLinesRef:V,calculateLinesDebounced:$t,handleColumnScroll:Rt}};
|
|
2
2
|
//# sourceMappingURL=useLinesCalculator.js.map
|