Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 270a592

Browse files
committedFeb 23, 2024·
cleanup
1 parent 1484790 commit 270a592

File tree

8 files changed

+22
-28
lines changed

8 files changed

+22
-28
lines changed
 

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

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
const {
2323
states: { paneGroupStyle, paneGroupSelectors, groupId },
2424
methods: { setLayout, getLayout },
25+
updateOption,
2526
} = setCtx({
2627
autoSaveId,
2728
direction,
@@ -31,6 +32,13 @@
3132
storage,
3233
});
3334
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+
3442
api = {
3543
getLayout,
3644
setLayout,

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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";
10+
import { resizeHandleAction } from "./pane-resizer.js";
1111
import type { PaneResizeHandleProps, PaneResizeHandleAttributes } from "./types.js";
1212
1313
type $$Props = PaneResizeHandleProps;
@@ -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;
@@ -102,7 +102,7 @@
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,
105+
"data-pane-resizer-id": resizeHandleId,
106106
} satisfies PaneResizeHandleAttributes;
107107
</script>
108108

‎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/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,5 @@ export type PaneResizeHandleAttributes = {
216216
/** Whether the resize handle is enabled or not. */
217217
"data-enabled"?: boolean;
218218
/** The ID of the resize handle. */
219-
"data-pane-resize-handle-id": string;
219+
"data-pane-resizer-id": string;
220220
};

‎packages/paneforge/src/lib/internal/paneforge.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ export function createPaneForge(props: CreatePaneForgeProps) {
508508
const handles = getResizeHandleElementsForGroup($groupId);
509509

510510
const unsubHandlers = handles.map((handle) => {
511-
const handleId = handle.getAttribute("data-pane-resize-handle-id");
511+
const handleId = handle.getAttribute("data-pane-resizer-id");
512512
if (!handleId) return noop;
513513

514514
const [idBefore, idAfter] = getResizeHandlePaneIds($groupId, handleId, get(paneDataArray));
@@ -643,7 +643,7 @@ function updateResizeHandleAriaValues({
643643
export function getResizeHandleElementsForGroup(groupId: string): HTMLElement[] {
644644
if (!isBrowser) return [];
645645
return Array.from(
646-
document.querySelectorAll(`[data-pane-resize-handle-id][data-pane-group-id="${groupId}"]`)
646+
document.querySelectorAll(`[data-pane-resizer-id][data-pane-group-id="${groupId}"]`)
647647
);
648648
}
649649

@@ -677,7 +677,7 @@ export function getResizeHandlePaneIds(
677677

678678
export function getResizeHandleElement(id: string): HTMLElement | null {
679679
if (!isBrowser) return null;
680-
const element = document.querySelector(`[data-pane-resize-handle-id="${id}"]`);
680+
const element = document.querySelector(`[data-pane-resizer-id="${id}"]`);
681681
if (element) {
682682
return element as HTMLElement;
683683
}
@@ -687,9 +687,7 @@ export function getResizeHandleElement(id: string): HTMLElement | null {
687687
export function getResizeHandleElementIndex(groupId: string, id: string): number | null {
688688
if (!isBrowser) return null;
689689
const handles = getResizeHandleElementsForGroup(groupId);
690-
const index = handles.findIndex(
691-
(handle) => handle.getAttribute("data-pane-resize-handle-id") === id
692-
);
690+
const index = handles.findIndex((handle) => handle.getAttribute("data-pane-resizer-id") === id);
693691
return index ?? null;
694692
}
695693

‎packages/paneforge/src/lib/internal/utils/lifecycle.ts

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
import { onDestroy, onMount } from "svelte";
2-
3-
/**
4-
* Safely calls `onMount` and catches any errors that occur.
5-
*/
6-
export function safeOnMount(fn: (...args: unknown[]) => unknown) {
7-
try {
8-
onMount(fn);
9-
} catch {
10-
return fn();
11-
}
12-
}
1+
import { onDestroy } from "svelte";
132

143
/**
154
* Safely calls `onDestroy` and catches any errors that occur.

‎packages/paneforge/src/lib/internal/utils/storage.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export function loadPaneGroupState(
100100

101101
/**
102102
* Saves the pane group state to local storage.
103-
* If the state is not found, returns null.
104103
*/
105104
export function savePaneGroupState(
106105
autoSaveId: string,
@@ -133,7 +132,7 @@ const debounceMap: {
133132
* Returns a debounced version of the given function.
134133
*/
135134
// eslint-disable-next-line @typescript-eslint/ban-types
136-
export default function debounce<T extends Function>(callback: T, durationMs: number = 10) {
135+
function debounce<T extends Function>(callback: T, durationMs: number = 10) {
137136
let timeoutId: NodeJS.Timeout | null = null;
138137

139138
// eslint-disable-next-line @typescript-eslint/no-explicit-any

‎sites/docs/content/components/pane-resize-handle.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ export type PaneResizeHandleAttributes = {
6666
/** Whether the resize handle is enabled or not. */
6767
"data-enabled"?: boolean;
6868
/** The ID of the resize handle. */
69-
"data-pane-resize-handle-id": string;
69+
"data-pane-resizer-id": string;
7070
};
7171
```

0 commit comments

Comments
 (0)
Please sign in to comment.