Add a Markdown Editor.

This commit is contained in:
Dan 2022-11-03 11:38:59 -04:00
parent ca2bc557f1
commit b7e094dc9f
4 changed files with 1121 additions and 8 deletions

1050
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -17,12 +17,13 @@
"@types/node": "^18.6.5", "@types/node": "^18.6.5",
"@types/react": "^18.0.17", "@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6", "@types/react-dom": "^18.0.6",
"@uiw/react-md-editor": "^3.19.5",
"autoprefixer": "10.4.8", "autoprefixer": "10.4.8",
"axios": "^0.27.2", "axios": "^0.27.2",
"bootstrap": "^5.2.0", "bootstrap": "^5.2.0",
"bpmn-js": "^9.3.2", "bpmn-js": "^9.3.2",
"bpmn-js-properties-panel": "^1.10.0", "bpmn-js-properties-panel": "^1.10.0",
"bpmn-js-spiffworkflow": "sartography/bpmn-js-spiffworkflow#main", "bpmn-js-spiffworkflow": "sartography/bpmn-js-spiffworkflow#feature/more_launch_buttons_and_dropdowns",
"craco": "^0.0.3", "craco": "^0.0.3",
"date-fns": "^2.28.0", "date-fns": "^2.28.0",
"diagram-js": "^8.5.0", "diagram-js": "^8.5.0",

View File

@ -68,6 +68,7 @@ type OwnProps = {
diagramXML?: string | null; diagramXML?: string | null;
fileName?: string; fileName?: string;
onLaunchScriptEditor?: (..._args: any[]) => any; onLaunchScriptEditor?: (..._args: any[]) => any;
onLaunchMarkdownEditor?: (..._args: any[]) => any;
onElementClick?: (..._args: any[]) => any; onElementClick?: (..._args: any[]) => any;
onServiceTasksRequested?: (..._args: any[]) => any; onServiceTasksRequested?: (..._args: any[]) => any;
url?: string; url?: string;
@ -86,6 +87,7 @@ export default function ReactDiagramEditor({
diagramXML, diagramXML,
fileName, fileName,
onLaunchScriptEditor, onLaunchScriptEditor,
onLaunchMarkdownEditor,
onElementClick, onElementClick,
onServiceTasksRequested, onServiceTasksRequested,
url, url,
@ -190,6 +192,17 @@ export default function ReactDiagramEditor({
} }
} }
function handleLaunchMarkdownEditor(
element: any,
value: string,
eventBus: any
) {
if (onLaunchMarkdownEditor) {
setPerformingXmlUpdates(true);
onLaunchMarkdownEditor(element, value, eventBus);
}
}
function handleElementClick(event: any) { function handleElementClick(event: any) {
if (onElementClick) { if (onElementClick) {
onElementClick(event.element); onElementClick(event.element);
@ -204,7 +217,7 @@ export default function ReactDiagramEditor({
setDiagramModelerState(diagramModeler); setDiagramModelerState(diagramModeler);
diagramModeler.on('script.editor.launch', (event: any) => { diagramModeler.on('spiff.script.edit', (event: any) => {
const { error, element, scriptType, script, eventBus } = event; const { error, element, scriptType, script, eventBus } = event;
if (error) { if (error) {
console.log(error); console.log(error);
@ -212,6 +225,14 @@ export default function ReactDiagramEditor({
handleLaunchScriptEditor(element, script, scriptType, eventBus); handleLaunchScriptEditor(element, script, scriptType, eventBus);
}); });
diagramModeler.on('spiff.markdown.edit', (event: any) => {
const { error, element, value, eventBus } = event;
if (error) {
console.log(error);
}
handleLaunchMarkdownEditor(element, value, eventBus);
});
// 'element.hover', // 'element.hover',
// 'element.out', // 'element.out',
// 'element.click', // 'element.click',
@ -229,6 +250,7 @@ export default function ReactDiagramEditor({
diagramModelerState, diagramModelerState,
diagramType, diagramType,
onLaunchScriptEditor, onLaunchScriptEditor,
onLaunchMarkdownEditor,
onElementClick, onElementClick,
onServiceTasksRequested, onServiceTasksRequested,
]); ]);

View File

@ -1,4 +1,4 @@
import { useContext, useEffect, useRef, useState } from 'react'; import {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import { useNavigate, useParams, useSearchParams } from 'react-router-dom'; import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
import { Button, Modal, Stack } from 'react-bootstrap'; import { Button, Modal, Stack } from 'react-bootstrap';
import Container from 'react-bootstrap/Container'; import Container from 'react-bootstrap/Container';
@ -7,6 +7,7 @@ import Col from 'react-bootstrap/Col';
import Editor from '@monaco-editor/react'; import Editor from '@monaco-editor/react';
import MDEditor from '@uiw/react-md-editor'
import ReactDiagramEditor from '../components/ReactDiagramEditor'; import ReactDiagramEditor from '../components/ReactDiagramEditor';
import ProcessBreadcrumb from '../components/ProcessBreadcrumb'; import ProcessBreadcrumb from '../components/ProcessBreadcrumb';
import HttpService from '../services/HttpService'; import HttpService from '../services/HttpService';
@ -26,6 +27,11 @@ export default function ProcessModelEditDiagram() {
const [showScriptEditor, setShowScriptEditor] = useState(false); const [showScriptEditor, setShowScriptEditor] = useState(false);
const handleShowScriptEditor = () => setShowScriptEditor(true); const handleShowScriptEditor = () => setShowScriptEditor(true);
const [markdownText, setMarkdownText] = useState<string | undefined>('');
const [markdownEventBus, setMarkdownEventBus] = useState<any>(null);
const [showMarkdownEditor, setShowMarkdownEditor] = useState(false);
const handleShowMarkdownEditor = () => setShowMarkdownEditor(true);
const editorRef = useRef(null); const editorRef = useRef(null);
const monacoRef = useRef(null); const monacoRef = useRef(null);
@ -298,7 +304,7 @@ export default function ProcessModelEditDiagram() {
}; };
const handleScriptEditorClose = () => { const handleScriptEditorClose = () => {
scriptEventBus.fire('script.editor.update', { scriptEventBus.fire('spiff.script.update', {
scriptType, scriptType,
script: scriptText, script: scriptText,
element: scriptElement, element: scriptElement,
@ -589,6 +595,46 @@ export default function ProcessModelEditDiagram() {
</Modal> </Modal>
); );
}; };
const onLaunchMarkdownEditor = (
element: any,
markdown: string,
eventBus: any
) => {
setMarkdownText(markdown || '');
setMarkdownEventBus(eventBus);
handleShowMarkdownEditor();
};
const handleMarkdownEditorClose = () => {
markdownEventBus.fire('spiff.markdown.update', {
value: markdownText,
});
setShowMarkdownEditor(false);
};
const markdownEditor = () => {
return (
<Modal
size="xl"
show={showMarkdownEditor}
onHide={handleMarkdownEditorClose}
>
<Modal.Header closeButton>
<Modal.Title>Edit Markdown Content</Modal.Title>
</Modal.Header>
<Modal.Body>
<MDEditor
value={markdownText}
onChange={setMarkdownText}
/>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleMarkdownEditorClose}>
Close
</Button>
</Modal.Footer>
</Modal>
);
};
const isDmn = () => { const isDmn = () => {
const fileName = params.file_name || ''; const fileName = params.file_name || '';
@ -631,6 +677,7 @@ export default function ProcessModelEditDiagram() {
diagramType="bpmn" diagramType="bpmn"
onLaunchScriptEditor={onLaunchScriptEditor} onLaunchScriptEditor={onLaunchScriptEditor}
onServiceTasksRequested={onServiceTasksRequested} onServiceTasksRequested={onServiceTasksRequested}
onLaunchMarkdownEditor={onLaunchMarkdownEditor}
/> />
); );
}; };
@ -651,6 +698,7 @@ export default function ProcessModelEditDiagram() {
{appropriateEditor()} {appropriateEditor()}
{newFileNameBox()} {newFileNameBox()}
{scriptEditor()} {scriptEditor()}
{markdownEditor()}
<div id="diagram-container" /> <div id="diagram-container" />
</> </>