import {
ClausePlugin,
VariablePlugin,
ConditionalPlugin,
ComputedPlugin
} from "@accordproject/cicero-ui";
const plugins = React.useMemo(
() =>
props.plugins
? props.plugins.concat([
VariablePlugin(),
ConditionalPlugin(),
ClausePlugin(),
ComputedPlugin()
])
: [VariablePlugin(), ConditionalPlugin(), ClausePlugin(), ComputedPlugin()],
[props.plugins]
);
A custom Slate plugin for using editable, highlighted variables within a clause. Using VariablePlugin to add a variable and define schema for the addition of variable in the format defined by slate.js as its used in the markdown-editor.
npm install @accordproject/cicero-ui
import { VariablePlugin } from '@accordproject/cicero-ui';
import { Editor } from 'slate-react'
const plugins = [VariablePlugin()];
<Editor
...
plugins={plugins}
/>
It returns an object like this:
{
name,
augmentSchema,
isEditable,
renderInline,
}
where augmentSchema
, isEditable
and renderInline
are functions.
augmentSchema
function returns a new schema for the addition of variable in the markdown editor in the format suggested by slate.js.
isEditable
function returns a boolean on checking whether the variable in the markdown editor is editable or not.
renderInline
function renders a variable inline to the text in the editor by returning a span tag with the props.
return (
<span id={id} {...attributes} className='variable'>
{" "}
{children}{" "}
</span>
);
A custom Slate plugin for using non-editable, highlighted computed fields within a clause. Use ComputedPlugin to add a computed field and define schema for the addition of a computed field in the format defined by slate.js as its used in the markdown-editor.
npm install @accordproject/cicero-ui
import { ComputedPlugin } from '@accordproject/cicero-ui';
import { Editor } from 'slate-react'
const plugins = [ComputedPlugin()];
<Editor
...
plugins={plugins}
/>
It returns an object like this:
{
name,
augmentSchema,
isEditable,
renderInline,
}
where augmentSchema
, isEditable
and renderInline
are functions.
augmentSchema
function returns a new schema for the addition of computed in the markdown editor in the format suggested by slate.js.
isEditable
function returns a boolean on checking whether the computed field in the markdown editor is editable or not.
renderInline
function renders a computed inline to the text in the editor by returning a span tag with the props.
return (
<span id={id} {...attributes} className='computed'>
{" "}
{children}{" "}
</span>
);
A custom Slate plugin for embedding a clause node within a document. View the demo
directory for more of an example.
npm install @accordproject/cicero-ui
import { ClausePlugin } from '@accordproject/cicero-ui';
import { Editor } from 'slate-react'
const plugins = [ClausePlugin()];
<Editor
...
plugins={plugins}
/>
clausePluginProps={{
loadTemplateObject: props.loadTemplateObject,
onClauseUpdated: props.parseClause,
pasteToContract: props.pasteToContract,
clauseProps: props.clauseProps,
clauseMap: props.clauseMap
}}
loadTemplateObject
:Function
(Required) - Loads a templateonClauseUpdated
:Function
(Required) - Called when the text of a clause changespasteToContract
:Function
(Required) - Loads a template via copy/pasteclauseProps
: (Required) - Props passed to theClauseComponent
{
name,
augmentSchema,
renderBlock,
isEditable,
onChange,
onPaste,
queries: {
findClauseNode,
isOutsideOfClause: isEditable,
isClauseSupported
}
}
where augmentSchema
, renderBlock
, onChange
, onPaste
, findClauseNode
, isOutsideOfClause
, and isClauseSupported
are functions.
augmentSchema
function returns a new schema for the addition of clause type in the markdown editor in the format suggested by slate.js.
renderBlock
function renders a clause inline to the text in the editor by returning a span tag with the props.
onChange
function handles the changes to the document.
onPaste
function keep track of all the things that just got pasted.
findClauseNode
function is used to find the clause node by clauseId.
isOutsideOfClause
function returns a boolean which allows us editing if we are outside of a Clause.
isClauseSupported
function returns a boolean which tells if the UI is valid.
A plugin to support variables corresponding to conditional blocks in templates enabling text which depends on a value of a Boolean variable in the model.
npm install @accordproject/cicero-ui
import { ConditionalPlugin } from '@accordproject/cicero-ui';
import { Editor } from 'slate-react'
const plugins = [ConditionalPlugin()];
<Editor
...
plugins={plugins}
/>
{
name,
augmentSchema,
isEditable,
renderInline,
}
where augmentSchema
, isEditable
and renderInline
are functions.
augmentSchema
function returns a new schema for the addition of conditional type in the markdown editor in the format suggested by slate.js.
isEditable
function returns a boolean on checking whether the conditional field in the markdown editor is editable or not.
renderInline
function renders a conditional inline to the text in the editor by returning a span tag with the props.
return (
<span id={id} {...attributes} className='computed'>
{" "}
{children}{" "}
</span>
);