Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added lint-errors.txt
Binary file not shown.
Binary file added lint.txt
Binary file not shown.
14 changes: 12 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@
"@google/genai": "^1.8.0",
"@mistralai/mistralai": "^1.7.3",
"@monaco-editor/react": "^4.6.0",
"@types/dompurify": "^3.0.5",
"@types/styled-components": "^5.1.34",
"antd": "^5.7.2",
"core-js": "^3.37.1",
"dompurify": "^3.3.1",
"highlight.js": "^11.10.0",
"html2pdf.js": "^0.14.0",
"immer": "^10.1.1",
Expand Down
3 changes: 2 additions & 1 deletion src/AgreementHtml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LoadingOutlined } from "@ant-design/icons";
import { Spin } from "antd";
import useAppStore from "./store/store";
import FullScreenModal from "./components/FullScreenModal";
import DOMPurify from 'dompurify';

function AgreementHtml({ loading, isModal }: { loading: boolean; isModal?: boolean }) {
const agreementHtml = useAppStore((state) => state.agreementHtml);
Expand Down Expand Up @@ -45,7 +46,7 @@ function AgreementHtml({ loading, isModal }: { loading: boolean; isModal?: boole
) : (
<div
className="agreement"
dangerouslySetInnerHTML={{ __html: agreementHtml }}
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(agreementHtml) }}
style={{ flex: 1, color: textColor, backgroundColor: backgroundColor }}
/>
)}
Expand Down
67 changes: 0 additions & 67 deletions src/components/CodeSelectionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { sendMessage } from '../ai-assistant/chatRelay';
import { CodeSelectionMenuProps } from '../types/components/AIAssistant.types';
import useAppStore from '../store/store';
import ReactMarkdown from "react-markdown";
import * as monaco from 'monaco-editor';

const CodeSelectionMenu: React.FC<CodeSelectionMenuProps> = ({
selectedText,
Expand Down Expand Up @@ -247,70 +246,4 @@ const CodeSelectionMenu: React.FC<CodeSelectionMenuProps> = ({
);
};

// eslint-disable-next-line react-refresh/only-export-components
export const useCodeSelection = (editorType: 'markdown' | 'concerto' | 'json') => {
const [selectedText, setSelectedText] = useState('');
const [menuPosition, setMenuPosition] = useState<{ x: number; y: number } | null>(null);
const [showMenu, setShowMenu] = useState(false);
const enableCodeSelectionMenu = useAppStore((state) => state.aiConfig?.enableCodeSelectionMenu ?? true);


const handleSelection = (editor: monaco.editor.IStandaloneCodeEditor) => {
const selection = editor.getSelection();
if (selection && !selection.isEmpty()) {
const selectedText = editor.getModel()?.getValueInRange(selection).trim();
if (selectedText && selectedText.length > 0) {
const position = editor.getScrolledVisiblePosition(selection.getStartPosition());
const editorContainer = editor.getDomNode()?.closest('.editorwrapper');
const editorRect = editorContainer?.getBoundingClientRect();

let x: number, y: number;

if (editorRect && position) {
x = Math.max(editorRect.left + 20, Math.min(position.left, editorRect.right - 150));
y = Math.max(editorRect.top + 20, Math.min(position.top, editorRect.bottom - 50));

x = Math.max(10, Math.min(x, window.innerWidth - 150));
y = Math.max(10, Math.min(y, window.innerHeight - 50));
} else if (position) {
x = Math.max(10, Math.min(position.left, window.innerWidth - 150));
y = Math.max(10, Math.min(position.top, window.innerHeight - 50));
} else {
return;
}

setSelectedText(selectedText);
setMenuPosition({
x: x,
y: y
});
setShowMenu(true);
}
} else {
setShowMenu(false);
}
}

const closeMenu = () => {
setShowMenu(false);
setSelectedText('');
setMenuPosition(null);
};

const MenuComponent = (enableCodeSelectionMenu && showMenu && selectedText && menuPosition) ? (
<CodeSelectionMenu
selectedText={selectedText}
position={menuPosition}
onClose={closeMenu}
editorType={editorType}
/>
) : null;

return {
handleSelection,
closeMenu,
MenuComponent
};
};

export default CodeSelectionMenu;
14 changes: 8 additions & 6 deletions src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const CustomFooter: React.FC = () => {
<Row justify="space-between" align="middle" gutter={[16, 16]}>
<Col xs={24} md={12}>
<Space direction="vertical" size="middle">
<Link href="https://www.accordproject.org" target="_blank">
<Link href="https://www.accordproject.org" target="_blank" rel="noopener noreferrer">
<Image
src="/logo.png"
alt="Template Playground"
Expand All @@ -48,7 +48,7 @@ const CustomFooter: React.FC = () => {
admin@accordproject.org
</Text>
</Link>
<Link href="https://discord.com/invite/Zm99SKhhtA" target="_blank">
<Link href="https://discord.com/invite/Zm99SKhhtA" target="_blank" rel="noopener noreferrer">
<Button
size="large"
style={{
Expand Down Expand Up @@ -119,6 +119,7 @@ const CustomFooter: React.FC = () => {
strong
href="https://accordproject.org/privacy"
target="_blank"
rel="noopener noreferrer"
style={{ color: "rgba(255, 255, 255, 0.85)" }}
>
trademark policy
Expand All @@ -128,6 +129,7 @@ const CustomFooter: React.FC = () => {
strong
href="https://accordproject.org/brand-assets"
target="_blank"
rel="noopener noreferrer"
style={{ color: "rgba(255, 255, 255, 0.85)" }}
>
brand assets
Expand All @@ -137,16 +139,16 @@ const CustomFooter: React.FC = () => {

<Col>
<Space>
<Link href="https://github.com/accordproject" target="_blank" style={{ color: "rgba(255, 255, 255, 0.85)" }}>
<Link href="https://github.com/accordproject" target="_blank" rel="noopener noreferrer" style={{ color: "rgba(255, 255, 255, 0.85)" }}>
<GithubOutlined style={{ fontSize: "17px" }} />
</Link>
<Link href="https://twitter.com/AccordHQ" target="_blank" style={{ color: "rgba(255, 255, 255, 0.85)" }}>
<Link href="https://twitter.com/AccordHQ" target="_blank" rel="noopener noreferrer" style={{ color: "rgba(255, 255, 255, 0.85)" }}>
<XOutlined style={{ fontSize: "17px" }} />
</Link>
<Link href="https://discord.com/invite/Zm99SKhhtA" target="_blank" style={{ color: "rgba(255, 255, 255, 0.85)" }}>
<Link href="https://discord.com/invite/Zm99SKhhtA" target="_blank" rel="noopener noreferrer" style={{ color: "rgba(255, 255, 255, 0.85)" }}>
<DiscordFilled style={{ fontSize: "17px" }} />
</Link>
<Link href="https://www.linkedin.com/company/accordproject/" target="_blank" style={{ color: "rgba(255, 255, 255, 0.85)" }}>
<Link href="https://www.linkedin.com/company/accordproject/" target="_blank" rel="noopener noreferrer" style={{ color: "rgba(255, 255, 255, 0.85)" }}>
<LinkedinFilled style={{ fontSize: "17px" }} />
</Link>
</Space>
Expand Down
2 changes: 1 addition & 1 deletion src/editors/ConcertoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useMonaco } from "@monaco-editor/react";
import { lazy, Suspense, useCallback, useEffect, useMemo } from "react";
import * as monaco from "monaco-editor";
import useAppStore from "../store/store";
import { useCodeSelection } from "../components/CodeSelectionMenu";
import { useCodeSelection } from "../hooks/useCodeSelection";
import { registerAutocompletion } from "../ai-assistant/autocompletion";

const MonacoEditor = lazy(() =>
Expand Down
2 changes: 1 addition & 1 deletion src/editors/JSONEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { lazy, Suspense, useMemo, useCallback } from "react";
import * as monaco from "monaco-editor";
import useAppStore from "../store/store";
import { useCodeSelection } from "../components/CodeSelectionMenu";
import { useCodeSelection } from "../hooks/useCodeSelection";
import { registerAutocompletion } from "../ai-assistant/autocompletion";

const MonacoEditor = lazy(() =>
Expand Down
2 changes: 1 addition & 1 deletion src/editors/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { lazy, Suspense, useMemo, useCallback, useEffect } from "react";
import useAppStore from "../store/store";
import { useMonaco } from "@monaco-editor/react";
import { useCodeSelection } from "../components/CodeSelectionMenu";
import { useCodeSelection } from "../hooks/useCodeSelection";
import type { editor } from "monaco-editor";
import { registerAutocompletion } from "../ai-assistant/autocompletion";

Expand Down
69 changes: 69 additions & 0 deletions src/hooks/useCodeSelection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { useState } from 'react';
import * as monaco from 'monaco-editor';
import useAppStore from '../store/store';
import CodeSelectionMenu from '../components/CodeSelectionMenu';

export const useCodeSelection = (editorType: 'markdown' | 'concerto' | 'json') => {
const [selectedText, setSelectedText] = useState('');
const [menuPosition, setMenuPosition] = useState<{ x: number; y: number } | null>(null);
const [showMenu, setShowMenu] = useState(false);
const enableCodeSelectionMenu = useAppStore((state) => state.aiConfig?.enableCodeSelectionMenu ?? true);


const handleSelection = (editor: monaco.editor.IStandaloneCodeEditor) => {
const selection = editor.getSelection();
if (selection && !selection.isEmpty()) {
const selectedText = editor.getModel()?.getValueInRange(selection).trim();
if (selectedText && selectedText.length > 0) {
const position = editor.getScrolledVisiblePosition(selection.getStartPosition());
const editorContainer = editor.getDomNode()?.closest('.editorwrapper');
const editorRect = editorContainer?.getBoundingClientRect();

let x: number, y: number;

if (editorRect && position) {
x = Math.max(editorRect.left + 20, Math.min(position.left, editorRect.right - 150));
y = Math.max(editorRect.top + 20, Math.min(position.top, editorRect.bottom - 50));

x = Math.max(10, Math.min(x, window.innerWidth - 150));
y = Math.max(10, Math.min(y, window.innerHeight - 50));
} else if (position) {
x = Math.max(10, Math.min(position.left, window.innerWidth - 150));
y = Math.max(10, Math.min(position.top, window.innerHeight - 50));
} else {
return;
}

setSelectedText(selectedText);
setMenuPosition({
x: x,
y: y
});
setShowMenu(true);
}
} else {
setShowMenu(false);
}
}

const closeMenu = () => {
setShowMenu(false);
setSelectedText('');
setMenuPosition(null);
};

const MenuComponent = (enableCodeSelectionMenu && showMenu && selectedText && menuPosition) ? (
<CodeSelectionMenu
selectedText={selectedText}
position={menuPosition}
onClose={closeMenu}
editorType={editorType}
/>
) : null;
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new hook file imports CodeSelectionMenu component at line 4, creating a circular dependency. The hook is meant to be used by editors that need the code selection functionality, but it imports the component that should use the hook's return value. This defeats the purpose of extracting the hook for modularity. The MenuComponent should be rendered by the consuming component (MarkdownEditor, JSONEditor, ConcertoEditor) instead of being created inside the hook. The hook should only return the state and handlers, not the JSX component.

Copilot uses AI. Check for mistakes.

return {
handleSelection,
closeMenu,
MenuComponent
};
};
3 changes: 2 additions & 1 deletion src/pages/MainContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AgreementData from "../editors/editorsContainer/AgreementData";
import TemplateModel from "../editors/editorsContainer/TemplateModel";
import TemplateMarkdown from "../editors/editorsContainer/TemplateMarkdown";
import useAppStore from "../store/store";
import DOMPurify from 'dompurify';
import { AIChatPanel } from "../components/AIChatPanel";
import ProblemPanel from "../components/ProblemPanel";
import SampleDropdown from "../components/SampleDropdown";
Expand Down Expand Up @@ -231,7 +232,7 @@ const MainContainer = () => {
<div
ref={downloadRef}
className="main-container-agreement"
dangerouslySetInnerHTML={{ __html: agreementHtml }}
dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(agreementHtml) }}
style={{
color: textColor,
backgroundColor: previewBackgroundColor,
Expand Down
18 changes: 18 additions & 0 deletions src/types/markdown-template.d.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move typescript typedef upstream to the @accordproject/markdown-template package.
There is an example in the concerto repository for creating typedefs from jsdocs.
accordproject/markdown-transform#648

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
declare module '@accordproject/markdown-template' {
import { ModelManager } from '@accordproject/concerto-core';

export class TemplateMarkTransformer {
fromMarkdownTemplate(options: {
fileName: string;
content: string;
modelManager: ModelManager;
templateKind?: string;
}): { getModelManager: () => ModelManager };

toMarkdownTemplate(parserManager: { getModelManager: () => ModelManager }): string;

generate(data: Record<string, unknown>, parserManager: { getModelManager: () => ModelManager }): string;

getVariables(parserManager: { getModelManager: () => ModelManager }): Record<string, unknown>;
}
}