Skip to content
This repository was archived by the owner on May 19, 2020. It is now read-only.

Commit fabcff6

Browse files
authored
Merge pull request #158 from accordproject/irmerk-dselman-mdtransform
Refactor to use markdown-slate transform
2 parents 5cdcf15 + 8895895 commit fabcff6

File tree

24 files changed

+4527
-2747
lines changed

24 files changed

+4527
-2747
lines changed

demo/src/index.js

+18-96
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,28 @@
1-
import React, { useCallback, useEffect, useState } from 'react';
1+
import React, {
2+
useCallback, useEffect, useState
3+
} from 'react';
24
import {
3-
Header, Menu, Grid, Rail, Segment
5+
Button, Grid, Header, Segment
46
} from 'semantic-ui-react';
57

6-
import { PluginManager, List, FromMarkdown } from '@accordproject/markdown-editor';
8+
import { SlateTransformer } from '@accordproject/markdown-slate';
79

810
import { render } from 'react-dom';
911
import 'semantic-ui-css/semantic.min.css';
10-
import ClauseEditor from '../../src/ClauseEditor';
1112
import ContractEditor from '../../src/ContractEditor';
12-
import ClausePlugin from '../../src/plugins/ClausePlugin';
13-
import VariablePlugin from '../../src/plugins/VariablePlugin';
1413

15-
const clausePlugin = ClausePlugin(null, null);
16-
const plugins = [List(), VariablePlugin(), clausePlugin];
17-
const pluginManager = new PluginManager(plugins);
18-
const fromMarkdown = new FromMarkdown(pluginManager);
14+
const slateTransformer = new SlateTransformer();
1915

2016
const templateUri = 'https://templates.accordproject.org/archives/[email protected]';
21-
const clauseText = `Acceptance of Delivery. "Party A" will be deemed to have completed its delivery obligations if in "Party B"'s opinion, the "Widgets" satisfies the Acceptance Criteria, and "Party B" notifies "Party A" in writing that it is accepting the "Widgets".
17+
const clauseText = `Acceptance of Delivery. <variable id="shipper" value="%22Party%20A%22"/> will be deemed to have completed its delivery obligations if in <variable id="receiver" value="%22Party%20B%22"/>'s opinion, the <variable id="deliverable" value="%22Widgets%22"/> satisfies the Acceptance Criteria, and <variable id="receiver" value="%22Party%20B%22"/> notifies <variable id="shipper" value="%22Party%20A%22"/> in writing that it is accepting the <variable id="deliverable" value="%22Widgets%22"/>.
2218
23-
Inspection and Notice. "Party B" will have 10 Business Days' to inspect and evaluate the "Widgets" on the delivery date before notifying "Party A" that it is either accepting or rejecting the "Widgets".
19+
Inspection and Notice. <variable id="receiver" value="%22Party%20B%22"/> will have <variable id="businessDays" value="10"/> Business Days' to inspect and evaluate the <variable id="deliverable" value="%22Widgets%22"/> on the delivery date before notifying <variable id="shipper" value="%22Party%20A%22"/> that it is either accepting or rejecting the <variable id="deliverable" value="%22Widgets%22"/>.
2420
25-
Acceptance Criteria. The "Acceptance Criteria" are the specifications the "Widgets" must meet for the "Party A" to comply with its requirements and obligations under this agreement, detailed in "Attachment X", attached to this agreement.`;
26-
27-
const getClauseMarkdown = async () => {
28-
const rewriteClauseText = await clausePlugin.rewriteClause(templateUri, clauseText);
29-
30-
const acceptanceOfDeliveryClause = `\`\`\` <clause src="${templateUri}" clauseid="123">
31-
${rewriteClauseText}
32-
\`\`\`
33-
`;
34-
35-
return fromMarkdown.convert(acceptanceOfDeliveryClause);
36-
};
21+
Acceptance Criteria. The "Acceptance Criteria" are the specifications the <variable id="deliverable" value="%22Widgets%22"/> must meet for the <variable id="shipper" value="%22Party%20A%22"/> to comply with its requirements and obligations under this agreement, detailed in <variable id="attachment" value="%22Attachment%20X%22"/>, attached to this agreement.`;
3722

3823
const getContractMarkdown = async () => {
39-
const rewriteClauseText = await clausePlugin.rewriteClause(templateUri, clauseText);
40-
4124
const acceptanceOfDeliveryClause = `\`\`\` <clause src="${templateUri}" clauseid="123">
42-
${rewriteClauseText}
25+
${clauseText}
4326
\`\`\`
4427
`;
4528

@@ -50,35 +33,18 @@ ${rewriteClauseText}
5033
5134
Fin.
5235
`;
53-
return fromMarkdown.convert(defaultContractMarkdown);
36+
return slateTransformer.fromMarkdown(defaultContractMarkdown);
5437
};
5538

5639
/**
57-
* A demo component that uses ContractEditor and
58-
* TemplateLoadingClauseEditor
40+
* A demo component that uses ContractEditor
5941
*/
6042
function Demo() {
61-
/**
62-
* Which demo is currently selected
63-
*/
64-
const [activeItem, setActiveItem] = useState('clauseEditor');
65-
66-
/**
67-
* Currently clause value
68-
*/
69-
const [clauseValue, setClauseValue] = useState(null);
70-
7143
/**
7244
* Currently contract value
7345
*/
7446
const [contractValue, setContractValue] = useState(null);
75-
76-
/**
77-
* Async rewrite of the markdown text to a slate value
78-
*/
79-
useEffect(() => {
80-
getClauseMarkdown().then(value => setClauseValue(value));
81-
}, []);
47+
const [lockTextState, setlockTextState] = useState(true);
8248

8349
/**
8450
* Async rewrite of the markdown text to a slate value
@@ -87,33 +53,13 @@ function Demo() {
8753
getContractMarkdown().then(value => setContractValue(value));
8854
}, []);
8955

90-
/**
91-
* Called when the data in the clause editor has been modified
92-
*/
93-
const onClauseChange = useCallback((value, markdown) => {
94-
console.log(markdown);
95-
setClauseValue(value);
96-
}, []);
97-
9856
/**
9957
* Called when the data in the contract editor has been modified
10058
*/
101-
const onContractChange = useCallback((value, markdown) => {
102-
// console.log(JSON.stringify(value.toJSON(), null, 4));
59+
const onContractChange = useCallback((value) => {
10360
setContractValue(value);
10461
}, []);
10562

106-
/**
107-
* Called when the data in the clause editor has been parsed
108-
*/
109-
const onParse = useCallback((newParseResult) => {
110-
// console.log('onParse', newParseResult);
111-
}, []);
112-
113-
const handleItemClick = useCallback((e, { name }) => {
114-
setActiveItem(name);
115-
}, []);
116-
11763
const editorProps = {
11864
BUTTON_BACKGROUND_INACTIVE: null,
11965
BUTTON_BACKGROUND_ACTIVE: null,
@@ -127,45 +73,21 @@ function Demo() {
12773
WIDTH: '600px',
12874
};
12975

130-
const demo = activeItem === 'clauseEditor'
131-
? <ClauseEditor
132-
lockText={true}
133-
value={clauseValue}
134-
onChange={onClauseChange}
135-
onParse={onParse}
136-
editorProps={editorProps}
137-
/>
138-
: <ContractEditor
139-
lockText={true}
76+
const demo = <ContractEditor
77+
lockText={lockTextState}
14078
value={contractValue}
14179
onChange={onContractChange}
14280
editorProps={editorProps}
14381
/>;
14482

14583
return (
14684
<div>
85+
<Button onClick={() => setlockTextState(!lockTextState)} >Toggle lockText</Button>
86+
<Header size='medium'>lockText state: {lockTextState.toString()}</Header>
14787
<Grid centered columns={2}>
14888
<Grid.Column>
14989
<Segment>
15090
{demo}
151-
<Rail position='left'>
152-
<Segment>
153-
<Menu vertical>
154-
<Menu.Item
155-
name='clauseEditor'
156-
active={activeItem === 'clauseEditor'}
157-
onClick={handleItemClick}
158-
>
159-
<Header as='h4'>Clause Editor</Header>
160-
<p>Edit a single clause.</p>
161-
</Menu.Item>
162-
<Menu.Item name='contractEditor' active={activeItem === 'contractEditor'} onClick={handleItemClick}>
163-
<Header as='h4'>Contract Editor</Header>
164-
<p>Adds multiple clauses to a rich-text contract.</p>
165-
</Menu.Item>
166-
</Menu>
167-
</Segment>
168-
</Rail>
16991
</Segment>
17092
</Grid.Column>
17193
</Grid>

0 commit comments

Comments
 (0)