This repository contains a WYSIWYG editor for markdown that conforms to the CommonMark specification which can handle Accord Project's smart contract technology.
The editor is based on React, Slate, and the Accord Project markdown-transform
project.
npm install @accordproject/ui-contract-editor @accordproject/markdown-slate slate slate-history slate-react semantic-ui-react semantic-ui-css
import { render } from 'react-dom';
import React, { useCallback, useState } from 'react';
import ContractEditor from '@accordproject/ui-contract-editor';
import { SlateTransformer } from '@accordproject/markdown-slate';
import 'semantic-ui-css/semantic.min.css';
const slateTransformer = new SlateTransformer();
const getContractSlateVal = () => {
const defaultContractMarkdown = `# Heading One
This is text. This is *italic* text. This is **bold** text. This is \`inline code\`. Fin.`;
return slateTransformer.fromMarkdown(defaultContractMarkdown);
};
const clausePropsObject = {
CLAUSE_DELETE_FUNCTION (function),
CLAUSE_EDIT_FUNCTION (function),
CLAUSE_TEST_FUNCTION (function),
}
const parseClauseFunction = () => { /* ... */ }
const loadTemplateObjectFunction = () => { /* ... */ }
const pasteToContractFunction = () => { /* ... */ }
const ContractEditorRenderer = () => {
const [slateValue, setSlateValue] = useState(() => {
const slate = getContractSlateVal();
return slate.document.children;
});
const onContractChange = useCallback((value) => { setSlateValue(value); }, []);
return (
<ContractEditor
value={slateValue}
lockText={false}
readOnly={false}
onChange={onContractChange}
clauseProps={clausePropsObject}
loadTemplateObject={loadTemplateObjectFunction}
pasteToContract={pasteToContractFunction}
onClauseUpdated={parseClauseFunction}
/>
);
}
render(<ContractEditorRenderer />, document.getElementById('root'));
While Storybook is running, if you make a change in a package that you want to see reflected in the demo, in a new terminal:
cd packages/ui-contract-editor
npm run build
Storybook will reload with the applied changes.
value
[OPTIONAL]: Anarray
which is the initial contents of the editor.lockText
[OPTIONAL]: Aboolean
to lock all non variable text.readOnly
[OPTIONAL]: Aboolean
to lock all text and remove the formatting toolbar.activeButton
[OPTIONAL]: Optionalobject
to change formatting button active state color{ background: '#FFF', symbol: '#000' }
onChange
[OPTIONAL]: A callbackfunction
called when the contents of the editor change. Argument:value
: The Slate nodesarray
representing all the rich text
loadTemplateObject
[OPTIONAL]: A callbackfunction
to load a template. Argument:uri
: URIstring
source for loading the template
onClauseUpdated
[OPTIONAL]: A callbackfunction
called when text inside of a clause is changed. Arguments:clause
: The Slate nodeobject
representation of the clausejustAdded
: Aboolean
indicating if this was just added (likely via a paste action)
pasteToContract
[OPTIONAL]: A callbackfunction
to load a clause template via copy/paste. Arguments:clauseid
: Datastring
from the clause in Slate to indicate auuid
src
: URIstring
source for loading the template
clauseProps
: Anobject
for the clauses in the editor which contains a deletion, edit, and test function, as well as a header title string and color for clause icons on hover see below.
clauseProps
:
You can support deletion, editing, and testing of the Clause Components within the ContractEditor
. An object may be passed down this component with the following possible functions:
clauseProps = {
CLAUSE_DELETE_FUNCTION, // (Function)
CLAUSE_EDIT_FUNCTION, // (Function)
CLAUSE_TEST_FUNCTION, // (Function)
HEADER_TITLE, // (String)
ICON_HOVER_COLOR, // (String)
}
Accord Project is an open source, non-profit, initiative working to transform contract management and contract automation by digitizing contracts. Accord Project operates under the umbrella of the Linux Foundation. The technical charter for the Accord Project can be found here.
The Accord Project technology is being developed as open source. All the software packages are being actively maintained on GitHub and we encourage organizations and individuals to contribute requirements, documentation, issues, new templates, and code.
Find out what’s coming on our blog.
Join the Accord Project Technology Working Group Slack channel to get involved!
For code contributions, read our CONTRIBUTING guide and information for DEVELOPERS.
Using Accord Project? Add a README badge to let everyone know:
[![accord project](https://img.shields.io/badge/powered%20by-accord%20project-19C6C8.svg)](https://www.accordproject.org/)
Accord Project source code files are made available under the Apache License, Version 2.0. Accord Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0).
Copyright 2018-2019 Clause, Inc. All trademarks are the property of their respective owners. See LF Projects Trademark Policy.