Skip to content

Commit 489010e

Browse files
authored
chore(docs): update docs for v0.2.x (#343)
* chore(docs): update docs for v0.2.x * chore: feedback
1 parent 2d7561f commit 489010e

File tree

8 files changed

+106
-18
lines changed

8 files changed

+106
-18
lines changed

site/docs/api/EditorState.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ import {API, Badge} from "@site/src/components";
1313
<API items={[
1414
["nodes", "Record<NodeId, Node>", "A map of all the Nodes in the editor"],
1515
["events", "Object", [
16-
["selected", "NodeId"],
17-
["hovered", "NodeId"],
18-
["dragged", "NodeId"],
16+
["selected", "Set<NodeId>"],
17+
["hovered", "Set<NodeId>"],
18+
["dragged", "Set<NodeId>"],
1919
]],
2020
["options", "Object", [
2121
["resolver", "Map<String, React.ComponentType>", "A map of User Components that will be used in the editor"],
2222
["enabled?", "boolean", "Optional. If set to false, all editing capabilities will be disabled"],
23-
["indicator?", 'Record<"success" | "error", String>', "Optional. The colour to use for the drop indicator. The colour set in 'success' will be used when the indicator shows a droppable location; otherwise the colour set in 'error' will be used."],
23+
["indicator", "Object", [
24+
["success", "String", "Color to use when the user hovers over a droppable location"],
25+
["error", "String", "Color to use when the usre hovers over a non-droppable location"],
26+
["transition", "string", "CSS transition to use for when the Indicator moves around"],
27+
["thickness", "number", "Thickness of the Indicator"]
28+
]],
2429
["onRender?", "React.ComponentType<{element: React.ReactElement}>", "Optional. Specify a custom component to render every User Element in the editor."],
2530
["onNodesChange?", "() => void", "Optional. A callback method when the values of any of the nodes in the state changes"]
2631
]]

site/docs/api/Node.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import {API, Badge} from "@site/src/components";
3535
["rules", "Object", [
3636
["canDrag", "(currentNode: Node) => boolean", "Specifies if the current Node can be dragged. Applicable only if the current Node is a direct child of a Canvas Node"],
3737
["canDrop", "(targetNode: Node, currentNode: Node) => boolean", "Specifies if the current Node that is being dragged can be dropped in its target. Applicable only if the current Node is a direct child of a Canvas Node"],
38-
["canMoveIn", "(incomingNode: Node, currentNode: Node) => boolean", "Specifies if an incoming Node can be dropped in the current Node. Applicable only if the current Node is a Canvas Node"],
39-
["canMoveOut", "(outgoingNode: Node, currentNode: Node) => boolean", "Specifies if a child Node can be dragged out of the current Node. Applicable only if the current Node is a Canvas Node"],
38+
["canMoveIn", "(incomingNodes: Node[], currentNode: Node, helpers: NodeHelpers) => boolean", "Specifies if an array of incoming Nodes can be dropped into the current component. Applicable only to components whose corresponding Node is a Canvas"],
39+
["canMoveOut", "(outgoingNodes: Node[], currentNode: Node, helpers: NodeHelpers) => boolean", "Specifies if an array of child Nodes can be dragged out of the current component. Applicable only to components whose corresponding Node is a Canvas"],
4040
]]
4141
]} />
4242

site/docs/api/NodeHelpers.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ MyComp.craft = {
3838
const ancestors = helper(node.id).ancestors();
3939
...
4040
},
41-
canMoveIn : (incoming: Node, self: Node, helper: NodeHelpers) => {
42-
const isRoot = helper(node.id).isRoot();
41+
canMoveIn : (incoming: Node[], self: Node, helper: NodeHelpers) => {
42+
const isRoot = helper(self.id).isRoot();
4343
...
4444
}
45-
canMoveOut: (outgoing: Node, self: Node, helper: NodeHelpers) => {
46-
const isDeletable = helper(node.id).isDeletable();
45+
canMoveOut: (outgoing: Node[], self: Node, helper: NodeHelpers) => {
46+
const isDeletable = helper(self.id).isDeletable();
4747
...
4848
}
4949
}

site/docs/api/UserComponent.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ A wrapper of `React.ComponentType<Props>`. Accepts a static `craft` property for
2323
["rules?", [
2424
["canDrag", "(currentNode: Node, helpers: NodeHelpers) => boolean", "Specifies if the component can be dragged. Applicable only to components whose corresponding Node is a direct child of a Canvas"],
2525
["canDrop", "(targetNode: Node, currentNode, helpers: NodeHelpers) => boolean", "Specifies if the current Node that is being dragged can be dropped in its target. Applicable only if the current Node is a direct child of a Canvas Node"],
26-
["canMoveIn", "(incomingNode: Node, currentNode: Node, helpers: NodeHelpers) => boolean", "Specifies if an incoming Node can be dropped into the current component. Applicable only to components whose corresponding Node is a Canvas"],
27-
["canMoveOut", "(outgoingNode: Node, currentNode: Node, helpers: NodeHelpers) => boolean", "Specifies if a child Node can be dragged out of the current component. Applicable only to components whose corresponding Node is a Canvas"],
26+
["canMoveIn", "(incomingNodes: Node[], currentNode: Node, helpers: NodeHelpers) => boolean", "Specifies if an array of incoming Nodes can be dropped into the current component. Applicable only to components whose corresponding Node is a Canvas"],
27+
["canMoveOut", "(outgoingNodes: Node[], currentNode: Node, helpers: NodeHelpers) => boolean", "Specifies if an array of child Nodes can be dragged out of the current component. Applicable only to components whose corresponding Node is a Canvas"],
2828
]],
2929
]]
3030
]]
@@ -61,8 +61,8 @@ TextComponent.craft = {
6161
},
6262
rules: {
6363
canDrag: (self: Node, helper) => true,
64-
canMoveIn: (incoming: Node, self: Node, helper) => true,
65-
canMoveOut: (outgoing: Node, self: Node, helper) => true
64+
canMoveIn: (incoming: Node[], self: Node, helper) => true,
65+
canMoveOut: (outgoing: Node[], self: Node, helper) => true
6666
},
6767
related: {
6868
settings: TextSettings

site/docs/guides/basic-tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ export const CardTop = ({children}) => {
494494
CardTop.craft = {
495495
rules: {
496496
// Only accept Text
497-
canMoveIn: (incomingNode) => incomingNode.data.type == Text
497+
canMoveIn: (incomingNodes) => incomingNodes.every(incomingNode => incomingNode.data.type === Text)
498498
}
499499
}
500500

@@ -510,7 +510,7 @@ export const CardBottom = ({children}) => {
510510
CardBottom.craft = {
511511
rules: {
512512
// Only accept Buttons
513-
canMoveIn : (incomingNode) => incomingNode.data.type == Button
513+
canMoveIn : (incomingNode) => incomingNodes.every(incomingNode => incomingNode.data.type === Button)
514514
}
515515
}
516516

site/docs/migrating/0.1.x.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
id: migrating-0.1.x
3+
title: Migrating from 0.1.x
4+
---
5+
6+
import {Image} from "@site/src/components";
7+
8+
## Multiselect
9+
10+
In version 0.2.x, we introduced Multiselect which required us to change the `EditorState`.
11+
12+
<Image src="https://user-images.githubusercontent.com/16416929/141787974-563e0864-d229-466e-8c62-3262987fef22.gif" />
13+
14+
15+
With multi-select, the `events` property from the `EditorState` is now `Set<NodeId>` rather than `NodeId`:
16+
17+
```tsx
18+
// 0.1.x
19+
type EditorState = {
20+
... // same as before
21+
events: NodeId;
22+
}
23+
24+
// 0.2.x
25+
type EditorState = {
26+
... // same as before
27+
events: Set<NodeId>;
28+
}
29+
```
30+
31+
### Update collected state values
32+
Therefore, you'll need to update any existing code that accesses the `events` property. For example, any state values collected via the `useEditor` hook:
33+
```tsx
34+
// 0.1.x
35+
const { selected, hovered, dragged } = useEditor(state => ({
36+
selected: state.events.selected === 'some-node-id',
37+
hovered: state.events.hovered === 'some-node-id',
38+
dragged: state.events.dragged === 'some-node-id',
39+
}))
40+
41+
// 0.2.x
42+
const { selected, hovered, dragged } = useEditor(state => ({
43+
selected: state.events.selected.has('some-node-id'),
44+
hovered: state.events.hovered.has('some-node-id'),
45+
dragged: state.events.dragged.has('some-node-id')
46+
}))
47+
```
48+
49+
### Update User Component rules
50+
Additionally, User Component `canMoveIn` and `canMoveOut` rules now accepts `Node[]` rather than `Node` as their first parameter. So, you may have to be update these rules for your components as well:
51+
52+
```tsx
53+
const Button = () => {
54+
return (...)
55+
}
56+
57+
// 0.1.x
58+
Button.craft = {
59+
rules: {
60+
canMoveIn: (incomingNode: Node, currentNode: Node, helpers: NodeHelpers) => {
61+
return incomingNode.data.name === 'Text';
62+
},
63+
canMoveOut: (outgoingNode: Node, currentNode: Node, helpers: NodeHelpers) => {
64+
return outgoingNode.data.name === 'Text';
65+
}
66+
}
67+
}
68+
69+
70+
// 0.2.x
71+
Button.craft = {
72+
rules: {
73+
canMoveIn: (incomingNodes: Node[], currentNode: Node, helpers: NodeHelpers) => {
74+
return incomingNodes.every(incomingNode => incomingNode.data.name === 'Text')
75+
},
76+
canMoveOut: (outgoingNodes: Node[], currentNOde: Node, helpers: NodeHelpers) => {
77+
return outgoingNodes.every(outgoingNode => outgoingNode.data.name === 'Text')
78+
}
79+
}
80+
}

site/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
module.exports = {
99
docs: {
10+
Migrating: ['migrating/migrating-0.1.x'],
1011
Introduction: ['overview', 'acknowledgements'],
1112
'Core Concepts': [
1213
'concepts/nodes',

site/src/components/Image.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from 'react';
22
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
33

4-
export const Image = ({ img }) => {
4+
export const Image = ({ img, src }) => {
55
const context = useDocusaurusContext();
66
const {
77
siteConfig: { baseUrl },
88
} = context;
99

10+
const imageSrc = src || `${baseUrl}img/${img}}`;
11+
1012
return (
1113
<div className="img-wrapper">
1214
<div>
@@ -15,7 +17,7 @@ export const Image = ({ img }) => {
1517
<div></div>
1618
<div></div>
1719
</header>
18-
<img src={`${baseUrl}img/${img}`} />
20+
<img src={imageSrc} />
1921
</div>
2022
</div>
2123
);

0 commit comments

Comments
 (0)