Skip to content

Commit 35e4f87

Browse files
authored
chore: cleanup and docs (#1)
1 parent 1484790 commit 35e4f87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+436
-309
lines changed

.changeset/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
33
"changelog": [
44
"@svitejs/changesets-changelog-github-compact",
5-
{ "repo": "huntabyte/paneforge" }
5+
{ "repo": "svecosystem/paneforge" }
66
],
77
"commit": false,
88
"fixed": [],

.changeset/old-years-press.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"paneforge": patch
3+
---
4+
5+
Initial release 🎉

README.md

+40
Original file line numberDiff line numberDiff line change
@@ -1 +1,41 @@
11
# Paneforge
2+
3+
PaneForge provides components that make it easy to create resizable panes in your Svelte apps. It's designed to be simple to use, and to work well with other Svelte components and libraries. This project has taken a lot of inspiration and code from the work done by [Bryan Vaughn](https://github.com/bvaughn) and [react-resizable-panels](https://github.com/bvaughn/react-resizable-panels) and seeks to provide a similar experience for Svelte developers.
4+
5+
## Features
6+
7+
- **Simple API**: PaneForge is designed to be easy to use. It provides a small set of components that can be combined to create complex layouts.
8+
- **Resizable Panes**: Panes can be resized by dragging the resizer between them.
9+
- **Nested Groups**: Groups of panes can be nested inside other groups to create complex layouts.
10+
- **Customizable**: The appearance and behavior of the panes can be customized using CSS and Svelte props.
11+
- **Persistent Layouts**: PaneForge can be used with LocalStorage or cookies to persist the layout of the panes between page loads.
12+
- **Accessible**: PaneForge is designed to be accessible to all users, including those who use assistive technologies.
13+
- **Community-driven**: PaneForge is an open-source project that welcomes contributions from the community. If you have an idea for a new feature or an improvement, we'd love to hear from you!
14+
15+
## Installation
16+
17+
```bash
18+
npm install paneforge
19+
```
20+
21+
## Basic Usage
22+
23+
Here's a simple example of how to use Paneforge to create a horizontal pane group with two panes:
24+
25+
```svelte
26+
<script lang="ts">
27+
import { PaneGroup, Pane, PaneResizer } from "paneforge";
28+
</script>
29+
30+
<PaneGroup direction="horizontal">
31+
<Pane defaultSize={50}>Pane 1</Pane>
32+
<PaneResizer />
33+
<Pane defaultSize={50}>Pane 2</Pane>
34+
</PaneGroup>
35+
```
36+
37+
The `PaneGroup` component is used to initialize a pane group, and the `Pane` component is used to create a pane. The `PaneResizer` component is used to create a resizer that can be dragged to resize the panes.
38+
39+
The components ship only with the styles necessary to position the panes in the appropriate layout. The rest of the styling is up to you.
40+
41+
For more information, see the [Documentation](https://paneforge.com).

packages/paneforge/.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"singleQuote": false,
44
"trailingComma": "es5",
55
"printWidth": 100,
6-
"plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
6+
"plugins": ["prettier-plugin-svelte"],
77
"overrides": [
88
{
99
"files": "*.svelte",

packages/paneforge/README.md

+26-43
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,41 @@
1-
# create-svelte
1+
# Paneforge
22

3-
Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
3+
PaneForge provides components that make it easy to create resizable panes in your Svelte apps. It's designed to be simple to use, and to work well with other Svelte components and libraries. This project has taken a lot of inspiration and code from the work done by [Bryan Vaughn](https://github.com/bvaughn) and [react-resizable-panels](https://github.com/bvaughn/react-resizable-panels) and seeks to provide a similar experience for Svelte developers.
44

5-
Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging).
5+
## Features
66

7-
## Creating a project
7+
- **Simple API**: PaneForge is designed to be easy to use. It provides a small set of components that can be combined to create complex layouts.
8+
- **Resizable Panes**: Panes can be resized by dragging the resizer between them.
9+
- **Nested Groups**: Groups of panes can be nested inside other groups to create complex layouts.
10+
- **Customizable**: The appearance and behavior of the panes can be customized using CSS and Svelte props.
11+
- **Persistent Layouts**: PaneForge can be used with LocalStorage or cookies to persist the layout of the panes between page loads.
12+
- **Accessible**: PaneForge is designed to be accessible to all users, including those who use assistive technologies.
13+
- **Community-driven**: PaneForge is an open-source project that welcomes contributions from the community. If you have an idea for a new feature or an improvement, we'd love to hear from you!
814

9-
If you're seeing this, you've probably already done this step. Congrats!
15+
## Installation
1016

1117
```bash
12-
# create a new project in the current directory
13-
npm create svelte@latest
14-
15-
# create a new project in my-app
16-
npm create svelte@latest my-app
18+
npm install paneforge
1719
```
1820

19-
## Developing
21+
## Basic Usage
2022

21-
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
23+
Here's a simple example of how to use Paneforge to create a horizontal pane group with two panes:
2224

23-
```bash
24-
npm run dev
25+
```svelte
26+
<script lang="ts">
27+
import { PaneGroup, Pane, PaneResizer } from "paneforge";
28+
</script>
2529
26-
# or start the server and open the app in a new browser tab
27-
npm run dev -- --open
30+
<PaneGroup direction="horizontal">
31+
<Pane defaultSize={50}>Pane 1</Pane>
32+
<PaneResizer />
33+
<Pane defaultSize={50}>Pane 2</Pane>
34+
</PaneGroup>
2835
```
2936

30-
Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.
31-
32-
## Building
37+
The `PaneGroup` component is used to initialize a pane group, and the `Pane` component is used to create a pane. The `PaneResizer` component is used to create a resizer that can be dragged to resize the panes.
3338

34-
To build your library:
39+
The components ship only with the styles necessary to position the panes in the appropriate layout. The rest of the styling is up to you.
3540

36-
```bash
37-
npm run package
38-
```
39-
40-
To create a production version of your showcase app:
41-
42-
```bash
43-
npm run build
44-
```
45-
46-
You can preview the production build with `npm run preview`.
47-
48-
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
49-
50-
## Publishing
51-
52-
Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).
53-
54-
To publish your library to [npm](https://www.npmjs.com):
55-
56-
```bash
57-
npm publish
58-
```
41+
For more information, see the [Documentation](https://paneforge.com).

packages/paneforge/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
},
1313
"scripts": {
1414
"dev": "pnpm watch",
15-
"build": "vite build && npm run package",
15+
"build": "pnpm package",
1616
"preview": "vite preview",
1717
"package": "svelte-kit sync && svelte-package && publint",
18-
"prepublishOnly": "npm run package",
18+
"prepublishOnly": "pnpm run package",
1919
"test": "npm run test:integration && npm run test:unit",
2020
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
2121
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { default as PaneGroup } from "./pane-group.svelte";
22
export { default as Pane } from "./pane.svelte";
3-
export { default as PaneResizeHandle } from "./pane-resize-handle.svelte";
3+
export { default as PaneResizer } from "./pane-resizer.svelte";
44
export type * from "./types.js";

packages/paneforge/src/lib/components/pane-group.svelte

+10-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
export let onLayoutChange: PaneGroupOnLayout | null = null;
1515
export let storage: PaneGroupStorage = defaultStorage as PaneGroupStorage;
1616
export let el: $$Props["el"] = undefined;
17-
export let api: $$Props["api"] = undefined;
17+
export let paneGroup: $$Props["paneGroup"] = undefined;
1818
1919
let styleFromProps: $$Props["style"] = undefined;
2020
export { styleFromProps as style };
2121
2222
const {
2323
states: { paneGroupStyle, paneGroupSelectors, groupId },
2424
methods: { setLayout, getLayout },
25+
updateOption,
2526
} = setCtx({
2627
autoSaveId,
2728
direction,
@@ -31,7 +32,14 @@
3132
storage,
3233
});
3334
34-
api = {
35+
$: updateOption("autoSaveId", autoSaveId);
36+
$: updateOption("direction", direction);
37+
$: updateOption("id", id);
38+
$: updateOption("keyboardResizeBy", keyboardResizeBy);
39+
$: updateOption("onLayout", onLayoutChange);
40+
$: updateOption("storage", storage);
41+
42+
paneGroup = {
3543
getLayout,
3644
setLayout,
3745
getId: () => $groupId,

packages/paneforge/src/lib/components/pane-resize-handle.svelte packages/paneforge/src/lib/components/pane-resizer.svelte

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import { getCursorStyle, generateId, styleToString } from "$lib/internal/utils/index.js";
88
import { onMount } from "svelte";
99
import { getCtx } from "./ctx.js";
10-
import { resizeHandleAction } from "./pane-resize-handle.js";
11-
import type { PaneResizeHandleProps, PaneResizeHandleAttributes } from "./types.js";
10+
import { resizeHandleAction } from "./pane-resizer.js";
11+
import type { PaneResizerProps, PaneResizerAttributes } from "./types.js";
1212
13-
type $$Props = PaneResizeHandleProps;
13+
type $$Props = PaneResizerProps;
1414
1515
export let disabled: $$Props["disabled"] = false;
1616
export let onDraggingChange: $$Props["onDraggingChange"] = undefined;
@@ -25,7 +25,7 @@
2525
const {
2626
methods: { registerResizeHandle, startDragging, stopDragging },
2727
states: { direction, dragState, groupId },
28-
} = getCtx("PaneResizeHandle");
28+
} = getCtx("PaneResizer");
2929
3030
const resizeHandleId = generateId(idFromProps);
3131
$: isDragging = $dragState?.dragHandleId === resizeHandleId;
@@ -98,12 +98,13 @@
9898
}) + styleFromProps ?? "";
9999
100100
$: attrs = {
101-
"data-pane-group-direction": $direction,
101+
"data-direction": $direction,
102102
"data-pane-group-id": $groupId,
103103
"data-active": isDragging ? "pointer" : isFocused ? "keyboard" : undefined,
104104
"data-enabled": !disabled,
105-
"data-pane-resize-handle-id": resizeHandleId,
106-
} satisfies PaneResizeHandleAttributes;
105+
"data-pane-resizer-id": resizeHandleId,
106+
"data-pane-resizer": "",
107+
} satisfies PaneResizerAttributes;
107108
</script>
108109

109110
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->

packages/paneforge/src/lib/components/pane-resize-handle.ts packages/paneforge/src/lib/components/pane-resizer.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
import { chain } from "$lib/internal/utils/chain.js";
77
import { addEventListener } from "$lib/internal/utils/event.js";
88

9-
type ResizeHandleActionParams = {
9+
type ResizerActionParams = {
1010
disabled?: boolean;
1111
resizeHandler: ResizeHandler | null;
1212
isDragging?: boolean;
@@ -18,9 +18,9 @@ type ResizeHandleActionParams = {
1818
* A Svelte action that adds resize handle functionality to an element.
1919
* This action is used to handle the dragging of a resize handle.
2020
*/
21-
export function resizeHandleAction(node: HTMLElement, params: ResizeHandleActionParams) {
21+
export function resizeHandleAction(node: HTMLElement, params: ResizerActionParams) {
2222
let unsub = () => {};
23-
function update(params: ResizeHandleActionParams) {
23+
function update(params: ResizerActionParams) {
2424
unsub();
2525
const { disabled, resizeHandler, isDragging, stopDragging, onDragging = undefined } = params;
2626
if (disabled || resizeHandler === null || !isDragging) return;

packages/paneforge/src/lib/components/pane.svelte

+6-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
export let onResize: $$Props["onResize"] = undefined;
1818
export let order: $$Props["order"] = undefined;
1919
export let el: $$Props["el"] = undefined;
20-
export let api: $$Props["api"] = undefined;
20+
export let pane: $$Props["pane"] = undefined;
2121
2222
let idFromProps: $$Props["id"] = undefined;
2323
export { idFromProps as id };
@@ -42,7 +42,9 @@
4242
4343
const paneId = generateId(idFromProps);
4444
45-
const paneData: PaneData = {
45+
let paneData: PaneData;
46+
47+
$: paneData = {
4648
callbacks: {
4749
onCollapse,
4850
onExpand,
@@ -60,7 +62,7 @@
6062
order,
6163
};
6264
63-
api = {
65+
pane = {
6466
collapse: () => {
6567
collapsePane(paneData);
6668
},
@@ -72,18 +74,8 @@
7274
getId: () => paneId,
7375
};
7476
75-
let paneHasBeenRegistered = false;
76-
77-
function handlePaneRegistration(_: number | undefined, __: string) {
78-
if (paneHasBeenRegistered) {
79-
unregisterPane(paneData);
80-
}
81-
82-
registerPane(paneData);
83-
}
84-
8577
onMount(() => {
86-
handlePaneRegistration(order, paneId);
78+
registerPane(paneData);
8779
8880
return () => {
8981
unregisterPane(paneData);

packages/paneforge/src/lib/components/types.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ export type PaneProps = {
7777
* An imperative API for the pane. `bind` to this prop to get access
7878
* to methods for controlling the pane.
7979
*/
80-
api?: PaneAPI;
80+
pane?: PaneAPI;
8181
} & Omit<HTMLAttributes<HTMLDivElement>, "id">;
8282

83-
export type PaneResizeHandleProps = {
83+
export type PaneResizerProps = {
8484
/**
8585
* Whether the resize handle is disabled.
8686
*
@@ -155,7 +155,7 @@ export type PaneGroupProps = {
155155
* An imperative API for the pane group. `bind` to this prop to get access
156156
* to methods for controlling the pane group.
157157
*/
158-
api?: PaneGroupAPI;
158+
paneGroup?: PaneGroupAPI;
159159
} & Omit<HTMLAttributes<HTMLDivElement>, "id">;
160160

161161
export type PaneAPI = {
@@ -201,20 +201,22 @@ export type PaneGroupAttributes = {
201201
/** Applied to every pane group element. */
202202
"data-pane-group": string;
203203
/** The direction of the pane group. */
204-
"data-pane-group-direction": Direction;
204+
"data-direction": Direction;
205205
/** The ID of the pane group. */
206206
"data-pane-group-id": string;
207207
};
208208

209-
export type PaneResizeHandleAttributes = {
210-
/** The direction of the pane group the handle belongs to. */
211-
"data-pane-group-direction": Direction;
212-
/** The ID of the pane group the handle belongs to. */
209+
export type PaneResizerAttributes = {
210+
/** Applied to all resizer elements */
211+
"data-pane-resizer": string;
212+
/** The direction of the pane group the resize handle belongs to. */
213+
"data-direction": Direction;
214+
/** The ID of the pane group the resize handle belongs to. */
213215
"data-pane-group-id": string;
214216
/** Whether the resize handle is active or not. */
215217
"data-active"?: "pointer" | "keyboard";
216218
/** Whether the resize handle is enabled or not. */
217219
"data-enabled"?: boolean;
218220
/** The ID of the resize handle. */
219-
"data-pane-resize-handle-id": string;
221+
"data-pane-resizer-id": string;
220222
};

packages/paneforge/src/lib/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
import type { PaneGroupStorage } from "$lib/internal/utils/storage.js";
2+
13
export * from "./components/index.js";
4+
export type { PaneGroupStorage };

0 commit comments

Comments
 (0)