Skip to content

Commit f943d20

Browse files
Merge pull request #11 from CarstenWickner/content-edit-functions
2 parents 3833981 + 4ff4167 commit f943d20

8 files changed

Lines changed: 423 additions & 70 deletions

File tree

CHANGELOG.MD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
### Added
9+
- Export of `updateStepData()` function for manipulating content of a single step node
10+
- Export of `updateGatewayData()` function for manipulating condition type associated with a single diverging gateway node
11+
- Export of `updateGatewayBranchData()` function for manipulating condition value associated with a single diverging gateway branch
12+
- Export of `validateFlow()` function (as alternative to `isFlowValid()`) throwing a descriptive error in case of an invalid flow
13+
714
## [1.0.1] - 2020-02-23
815
### Added
916
- Mentioning of all component props in README
@@ -28,5 +35,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2835
- Enable customization of default condition type, number of branches and associated condition values for a newly added `DivergingGatewayNode`
2936
- Expose internal validation logic
3037

38+
[Unreleased]: https://github.com/CarstenWickner/react-jsonschema-inspector/compare/v1.0.1...HEAD
3139
[1.0.1]: https://github.com/CarstenWickner/react-jsonschema-inspector/compare/v1.0.0...v1.0.1
3240
[1.0.0]: https://github.com/CarstenWickner/react-jsonschema-inspector/releases/tag/v1.0.0

README.md

Lines changed: 97 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@ Introducing a component for viewing/editing simple flow-charts but with the abil
88
The layout is handled through CSS `grid` which avoids error-prone pixel calculations.
99
The limited flexibility is accepted and even desired to concentrate on the more important content while still achieving a uniform design.
1010

11+
Topics covered in this document are:
12+
- [Demo](#demo)
13+
- [Usage](#usage)
14+
- [Installation from NPM](#installation-from-npm)
15+
- [React Component Props of `<FlowModeler>`](#react-component-props-of-flowmodeler)
16+
- [`flow` (required)](#flow-required)
17+
- [`options`](#options)
18+
- [`renderStep` (required)](#renderstep-required)
19+
- [`renderGatewayConditionType`](#rendergatewayconditiontype)
20+
- [`renderGatewayConditionValue`](#rendergatewayconditionvalue)
21+
- [`onChange`](#onchange)
22+
- [`editActions`](#editactions)
23+
- [Additional Exports](#additional-exports)
24+
- [`isFlowValid` function](#isflowvalid-function)
25+
- [`validateFlow` function](#validateflow-function)
26+
- [`updateStepData` function](#updatestepdata-function)
27+
- [`updateGatewayData` function](#updategatewaydata-function)
28+
- [`updateGatewayBranchData` function](#updategatewaybranchdata-function)
29+
- [Example (read-only)](#example-read-only)
30+
- [Example (structural editing, starting with empty "flow")](#example-structural-editing-starting-with-empty-flow)
31+
1132
## Demo
1233

1334
Have a look at the [![Storybook][storybook-image]][storybook-url]
@@ -26,14 +47,14 @@ npm i react-flow-modeler
2647
Describing the whole data model being displayed, expecting an object with two fields:
2748
- `flow.firstElementId` – string containing the key to the `flow.elements` entry, that should follow the start node
2849
- `flow.elements` – object containing all "step" nodes and "diverging gateway" nodes as values
29-
- "step" nodes are represented by an object that may contain the following fields:
30-
- `data` – object in which any kind of additional information may be stored (in order to consider it in the `renderStep` function
31-
- `nextElementId` – string containing the key to the `flow.elements` entry, that should follow this step (if omitted or without matching entry in `flow.elements`, it will point to the end node)
32-
- "diverging gateway" nodes are represented by an object that may contain the following fields:
33-
- `data` – object in which any kind of additional information may be stored (in order to consider it in the `renderGatewayConditionType` function
34-
- `nextElements` (required, otherwise it is treated as "step" node) – array of branches from this gateway, each branch being represented by an object with the following fields:
35-
- `conditionData` – object in which any kind of additional information may be stored (in order to consider it in the `renderGatewayConditionValue` function
36-
- `id` – string containing the key to the `flow.elements` entry, that should follow this gateway branch (if omitted or without matching entry in `flow.elements`, it will point to the end node)
50+
- "step" nodes are represented by an object that may contain the following fields:
51+
- `data` – object in which any kind of additional information may be stored (in order to consider it in the `renderStep` function
52+
- `nextElementId` – string containing the key to the `flow.elements` entry, that should follow this step (if omitted or without matching entry in `flow.elements`, it will point to the end node)
53+
- "diverging gateway" nodes are represented by an object that may contain the following fields:
54+
- `data` – object in which any kind of additional information may be stored (in order to consider it in the `renderGatewayConditionType` function
55+
- `nextElements` (required, otherwise it is treated as "step" node) – array of branches from this gateway, each branch being represented by an object with the following fields:
56+
- `conditionData` – object in which any kind of additional information may be stored (in order to consider it in the `renderGatewayConditionValue` function
57+
- `id` – string containing the key to the `flow.elements` entry, that should follow this gateway branch (if omitted or without matching entry in `flow.elements`, it will point to the end node)
3758

3859
#### `options`
3960
Currently only catering for one setting:
@@ -64,35 +85,82 @@ Render function for the condition label on a branch from a diverging gateway exp
6485
- `followingElement` – reference to the directly following element in the flow
6586

6687
#### `onChange`
67-
Callback function that when present enables structural editing, receiving a single input object containing the following field:
68-
- `changedFlow` – updated `flow` that should be stored in some external state and provided again via the `flow` prop
88+
Callback function that when present enables structural editing,
89+
- receiving a single input object containing the following field:
90+
- `changedFlow` – updated `flow` that should be stored in some external state and provided again via the `flow` prop to the `<Modeler>`
6991

7092
#### `editActions`
7193
Object containing various customization options for the structural editing feature in the following fields:
7294
- `addDivergingBranch` – object for customizing the adding of branches to a diverging gateway, expecting any of the following fields:
73-
- `className` – string overriding the default `"menu-item add-branch"` css classes on the corresponding context menu item
74-
- `title` – string defining the tool-tip to show for the corresponding context menu item
75-
- `isActionAllowed` – function for preventing adding branches to certain gateway, expecting a `boolean` to be returned based on the same single input object as on `renderGatewayConditionType` referring to the selected element
76-
- `getBranchConditionData` – function for providing the default `conditionData` on a newly added diverging gateway branch based on the same single input object as on `renderGatewayConditionType`
95+
- `className` – string overriding the default `"menu-item add-branch"` css classes on the corresponding context menu item
96+
- `title` – string defining the tool-tip to show for the corresponding context menu item
97+
- `isActionAllowed` – function for preventing adding branches to certain gateway, expecting a `boolean` to be returned based on the same single input object as on `renderGatewayConditionType` referring to the selected element
98+
- `getBranchConditionData` – function for providing the default `conditionData` on a newly added diverging gateway branch based on the same single input object as on `renderGatewayConditionType`
7799
- `addFollowingStepElement` – object for customizing the adding of step nodes, expecting any of the following fields:
78-
- `className` – string overriding the default `"menu-item add-step"` css classes on the corresponding context menu item
79-
- `title` – string defining the tool-tip to show for the corresponding context menu item
80-
- `isActionAllowed` – function for preventing adding step nodes after certain elements, expecting a `boolean` to be returned based on the reference to the selected element
81-
- `getStepData` – function for providing the default `data` on a newly added step node based on the reference to the element where the corresponding context menu item was clicked
100+
- `className` – string overriding the default `"menu-item add-step"` css classes on the corresponding context menu item
101+
- `title` – string defining the tool-tip to show for the corresponding context menu item
102+
- `isActionAllowed` – function for preventing adding step nodes after certain elements, expecting a `boolean` to be returned based on the reference to the selected element
103+
- `getStepData` – function for providing the default `data` on a newly added step node based on the reference to the element where the corresponding context menu item was clicked
82104
- `addFollowingDivergingGateway` – object for customizing the adding of diverging gateway nodes, expecting any of the following fields:
83-
- `className` – string overriding the default `"menu-item add-gateway"` css classes on the corresponding context menu item
84-
- `title` – string defining the tool-tip to show for the corresponding context menu item
85-
- `isActionAllowed` – function for preventing adding diverging gateways after certain elements, expecting a `boolean` to be returned based on the reference to the element where the corresponding context menu item was clicked
86-
- `getGatewayData` – function for providing the default `data` on a newly added diverging gateway based on the reference to the selected element
87-
- `getBranchConditionData`– function for providing an array of the default `conditionData` objects for each branch of a newly added diverging gateway based on the reference to the element where the corresponding context menu item was clicked; thereby also determining how many branches there are by default
105+
- `className` – string overriding the default `"menu-item add-gateway"` css classes on the corresponding context menu item
106+
- `title` – string defining the tool-tip to show for the corresponding context menu item
107+
- `isActionAllowed` – function for preventing adding diverging gateways after certain elements, expecting a `boolean` to be returned based on the reference to the element where the corresponding context menu item was clicked
108+
- `getGatewayData` – function for providing the default `data` on a newly added diverging gateway based on the reference to the selected element
109+
- `getBranchConditionData`– function for providing an array of the default `conditionData` objects for each branch of a newly added diverging gateway based on the reference to the element where the corresponding context menu item was clicked; thereby also determining how many branches there are by default
88110
- `changeNextElement` – object for customizing the links between elements in the flow, expecting any of the following fields:
89-
- `className` – string overriding the default `"menu-item change-next"` css classes on the corresponding context menu item
90-
- `title` – string defining the tool-tip to show for the corresponding context menu item
91-
- `isActionAllowed` – function for preventing links from certain elements to be changed, expecting a `boolean` to be returned based on the reference to the selected element
111+
- `className` – string overriding the default `"menu-item change-next"` css classes on the corresponding context menu item
112+
- `title` – string defining the tool-tip to show for the corresponding context menu item
113+
- `isActionAllowed` – function for preventing links from certain elements to be changed, expecting a `boolean` to be returned based on the reference to the selected element
92114
- `removeElement` – object for customizing the removal of elements in the flow, expecting any of the following fields:
93-
- `className` – string overriding the default `"menu-item remove"` css classes on the corresponding context menu item
94-
- `title` – string defining the tool-tip to show for the corresponding context menu item
95-
- `isActionAllowed` – function for preventing certain elements to be removed, expecting a `boolean` to be returned based on the reference to the selected element
115+
- `className` – string overriding the default `"menu-item remove"` css classes on the corresponding context menu item
116+
- `title` – string defining the tool-tip to show for the corresponding context menu item
117+
- `isActionAllowed` – function for preventing certain elements to be removed, expecting a `boolean` to be returned based on the reference to the selected element
118+
119+
### Additional Exports
120+
#### `isFlowValid` function
121+
- input: expecting a complete `flow` as single input parameter
122+
- output: returning a `boolean` response to indicate whether the given `flow` is deemed valid by the `<Modeler>`
123+
124+
#### `validateFlow` function
125+
- input: expecting a complete `flow` as single input parameter
126+
- output: not returning anything in case of a valid `flow` but throwing an `Error` otherwise
127+
128+
#### `updateStepData` function
129+
- inputs:
130+
1. expecting a complete `flow` as first input parameter
131+
2. expecting the `id` of a step node (i.e. identifying the step node under `flow.elements[id]`) as second input parameter
132+
3. expecting a callback function as third input parameter
133+
- input: the current `data` of the targeted step node will be provided as single input parameter
134+
- output: the new `data` object to set on the targeted step node is expected to be returned
135+
- output: returning an object (that can be provided to your `onChange` function) containing the following field:
136+
- `changedFlow` – updated `flow` that should be stored in some external state and provided again via the `flow` prop to the `<Modeler>`
137+
138+
#### `updateGatewayData` function
139+
- inputs:
140+
1. expecting a complete `flow` as first input parameter
141+
2. expecting the `id` of a gateway node (i.e. identifying the gateway node under `flow.elements[id]`) as second input parameter
142+
3. expecting a callback function as third input parameter
143+
- input: the current `data` of the targeted gateway node will be provided as single input parameter
144+
- output: the new `data` object to set on the targeted gateway node is expected to be returned
145+
4. optionally catering for another callback function to be provided as fourth input parameter
146+
- inputs:
147+
1. the current `conditionData` of a branch of the targeted gateway node will be provided as first input parameter
148+
2. the index of the respective branch of the targeted gateway node will be provided as second input parameter
149+
3. an array of the current `conditionData` of all branches of the targeted gateway node will be provided as third input parameter
150+
- ooutput: the new `conditionData` object to set on the respective branch of the targeted gateway node is expected to be returned
151+
- output: returning an object (that can be provided to your `onChange` function) containing the following field:
152+
- `changedFlow` – updated `flow` that should be stored in some external state and provided again via the `flow` prop to the `<Modeler>`
153+
154+
#### `updateGatewayBranchData` function
155+
- inputs:
156+
1. expecting a complete `flow` as first input parameter
157+
2. expecting the `id` of a gateway node (i.e. identifying the gateway node under `flow.elements[id]`) as second input parameter
158+
3. expecting the index of the targeted branch of the gateway node (i.e. referring to `flow.elements[id].nextElements[index]`) as third input parameter
159+
4. expecting a callback function as fourth input parameter
160+
- input: the current `conditionData` of the targeted gateway branch will be provided as single input parameter
161+
- output: the new `conditionData` object to set on the targeted gateway branch is expected to be returned
162+
- output: returning an object (that can be provided to your `onChange` function) containing the following field:
163+
- `changedFlow` – updated `flow` that should be stored in some external state and provided again via the `flow` prop to the `<Modeler>`
96164

97165
### Example (read-only)
98166
```javascript

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-flow-modeler",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Modeler for customisable flow charts",
55
"homepage": "https://CarstenWickner.github.io/react-flow-modeler/?path=/docs/flowmodeler--show-case",
66
"author": "Carsten Wickner",

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
export { FlowModeler } from "./component/FlowModeler";
22

3-
export { isFlowValid } from "./model/pathValidationUtils";
3+
export { updateStepData, updateGatewayData, updateGatewayBranchData } from "./model/modelUtils";
4+
5+
export { isFlowValid, validateFlow } from "./model/pathValidationUtils";

0 commit comments

Comments
 (0)