react-headless-dock-layout 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +48 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -21,6 +21,10 @@ A lightweight, headless dock layout library for React.
21
21
  - You want a complete IDE-like layout system
22
22
 
23
23
 
24
+ ## Requirements
25
+
26
+ - React >= 18.0.0
27
+
24
28
  ## Installation
25
29
 
26
30
  ```bash
@@ -111,3 +115,47 @@ function App() {
111
115
  );
112
116
  }
113
117
  ```
118
+
119
+ ## Advanced
120
+
121
+ ### Placement Strategies
122
+
123
+ A placement strategy determines where new panels are placed when added. The default strategy is `equalWidthRightStrategy`, which adds panels to the right with equal widths.
124
+
125
+ To use a custom strategy, pass it in the options. Here's an example that adds panels to the rightmost panel, alternating split directions:
126
+
127
+ ```tsx
128
+ import { useDockLayout, type PlacementStrategy, type LayoutNode, type PanelNode, type SplitNode } from 'react-headless-dock-layout';
129
+
130
+ function findRightMostPanel(node: LayoutNode): PanelNode {
131
+ if (node.type === "panel") return node;
132
+ if (node.type === "split") return findRightMostPanel(node.right);
133
+ throw new Error("Unexpected node type");
134
+ }
135
+
136
+ function findParentNode(root: LayoutNode, id: string): SplitNode | null {
137
+ function find(node: LayoutNode): SplitNode | null {
138
+ if (node.type === "panel") return null;
139
+ if (node.left.id === id || node.right.id === id) return node;
140
+ return find(node.left) ?? find(node.right);
141
+ }
142
+ return find(root);
143
+ }
144
+
145
+ const myStrategy: PlacementStrategy = {
146
+ getPlacementOnAdd(root) {
147
+ const rightMostPanel = findRightMostPanel(root);
148
+ const parentNode = findParentNode(root, rightMostPanel.id);
149
+
150
+ return {
151
+ targetId: rightMostPanel.id,
152
+ direction: parentNode?.orientation === "horizontal" ? "bottom" : "right",
153
+ ratio: 0.5,
154
+ };
155
+ },
156
+ };
157
+
158
+ const { addPanel } = useDockLayout(null, {
159
+ placementStrategy: myStrategy,
160
+ });
161
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-headless-dock-layout",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "A lightweight, headless dock layout library for React.",
5
5
  "type": "module",
6
6
  "exports": {