Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Jul 30, 2024
1 parent 2b21048 commit 4149691
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 84 deletions.
11 changes: 3 additions & 8 deletions packages/paneforge/src/lib/components/pane-group.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
onLayoutChange = noop,
storage = defaultStorage,
ref = $bindable(null),
setPaneGroupApi = noop,
child,
children,
...restProps
Expand All @@ -32,13 +31,9 @@
storage: box.with(() => storage),
});
$effect(() => {
setPaneGroupApi({
getLayout: () => paneGroupState.layout,
setLayout: paneGroupState.setLayout,
getId: () => paneGroupState.id.current,
});
});
export const getLayout = () => paneGroupState.layout;
export const setLayout = paneGroupState.setLayout;
export const getId = () => paneGroupState.id.current;
const mergedProps = $derived(mergeProps(restProps, paneGroupState.props));
</script>
Expand Down
14 changes: 7 additions & 7 deletions packages/paneforge/src/lib/components/pane.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import { box, mergeProps } from "svelte-toolbelt";
import { untrack } from "svelte";
import type { PaneProps } from "./types.js";
import { noop } from "$lib/internal/helpers.js";
import { useId } from "$lib/internal/utils/useId.js";
Expand All @@ -9,7 +8,6 @@
let {
id = useId(),
ref = $bindable(null),
setPaneApi = noop,
collapsedSize,
collapsible,
defaultSize,
Expand Down Expand Up @@ -41,11 +39,13 @@
order: box.with(() => order),
});
$effect(() => {
untrack(() => {
setPaneApi(paneState.pane);
});
});
export const collapse = paneState.pane.collapse;
export const expand = paneState.pane.expand;
export const getSize = paneState.pane.getSize;
export const isCollapsed = paneState.pane.isCollapsed;
export const isExpanded = paneState.pane.isExpanded;
export const resize = paneState.pane.resize;
export const getId = paneState.pane.getId;
const mergedProps = $derived(mergeProps(restProps, paneState.props));
</script>
Expand Down
12 changes: 0 additions & 12 deletions packages/paneforge/src/lib/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ export type PanePropsWithoutHTML = WithChild<{
* A callback that is called when the pane is resized.
*/
onResize?: PaneOnResize | undefined;

/**
* A callback that receives an imperative API for the pane. You can assign
* this to a variable to programmatically control the pane.
*/
setPaneApi?: (api: PaneAPI) => void;
}>;

export type PaneProps = PanePropsWithoutHTML &
Expand Down Expand Up @@ -130,12 +124,6 @@ export type PaneGroupPropsWithoutHTML = WithChild<{
* The storage object to use for saving the layout of the panes in the group.
*/
storage?: PaneGroupStorage | undefined;

/**
* A callback that receives an imperative API for the pane group. You can assign
* this to a variable to programmatically control the pane group.
*/
setPaneGroupApi?: (api: PaneGroupAPI) => void;
}>;

export type PaneGroupProps = PaneGroupPropsWithoutHTML &
Expand Down
2 changes: 1 addition & 1 deletion packages/paneforge/src/lib/internal/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export function validatePaneGroupLayout({
initialSize: unsafeSize,
});

if (unsafeSize != safeSize) {
if (unsafeSize !== safeSize) {
remainingSize += unsafeSize - safeSize;

nextLayout[index] = safeSize;
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion packages/paneforge/src/lib/internal/utils/adjust-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function adjustLayoutByDelta({
// A positive delta means the pane(s) immediately before the resize handle should "expand".
// This is accomplished by shrinking/contracting (and shifting) one or more of the panes after the resize handle.

// eslint-disable-next-line no-lone-blocks
{
// If this is a resize triggered by a keyboard event, our logic for expanding/collapsing is different.
// We no longer check the halfway threshold because this may prevent the pane from expanding at all.
Expand Down Expand Up @@ -109,7 +110,6 @@ export function adjustLayoutByDelta({

while (true) {
const prevSize = prevLayout[index];
console.log("prevSize", prevSize);
assert(prevSize != null);

const maxSafeSize = resizePane({
Expand Down
2 changes: 1 addition & 1 deletion packages/paneforge/src/lib/internal/utils/assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function assert(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line ts/no-explicit-any
expectedCondition: any,
message: string = "Assertion failed!"
): asserts expectedCondition {
Expand Down
1 change: 0 additions & 1 deletion packages/paneforge/src/lib/internal/utils/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type NonEmptyArray<T> = [T, ...T[]];
/**
* Executes an array of callback functions with the same arguments.
* @template T The types of the arguments that the callback functions take.
* @param n array of callback functions to execute.
* @returns A new function that executes all of the original callback functions with the same arguments.
*/
export function chain<T extends unknown[]>(
Expand Down
Empty file.
12 changes: 0 additions & 12 deletions packages/paneforge/src/lib/internal/utils/lifecycle.ts

This file was deleted.

6 changes: 2 additions & 4 deletions packages/paneforge/src/lib/internal/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { type Writable, get } from "svelte/store";
import type { SvelteMap } from "svelte/reactivity";
import type { PaneData } from "../types.js";
import { LOCAL_STORAGE_DEBOUNCE_INTERVAL } from "../constants.js";

Expand Down Expand Up @@ -130,11 +128,11 @@ const debounceMap: {
/**
* Returns a debounced version of the given function.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line ts/no-unsafe-function-type
function debounce<T extends Function>(callback: T, durationMs: number = 10) {
let timeoutId: NodeJS.Timeout | null = null;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
// eslint-disable-next-line ts/no-explicit-any
const callable = (...args: any) => {
if (timeoutId !== null) {
clearTimeout(timeoutId);
Expand Down
17 changes: 0 additions & 17 deletions packages/paneforge/src/lib/internal/utils/style.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
import type { DragState, PaneData } from "../types.js";

/**
* A utility function that converts a style object to a string,
* which can be used as the value of the `style` attribute for
* an element.
*
* @param style - The style object to convert
* @returns The style object as a string
*/
export function styleToString(style: StyleObject): string {
return Object.keys(style).reduce((str, key) => {
if (style[key] === undefined) return str;
return `${str}${key}:${style[key]};`;
}, "");
}

export type StyleObject = Record<string, number | string | undefined>;

type CursorState =
| "horizontal"
| "horizontal-max"
Expand Down
30 changes: 13 additions & 17 deletions packages/paneforge/src/lib/paneforge.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@ import {
executeCallbacks,
useRefById,
} from "svelte-toolbelt";
import { isKeyDown, isMouseEvent, isTouchEvent } from "$lib/internal/utils/is.js";
import { onMount, untrack } from "svelte";
import { adjustLayoutByDelta } from "$lib/internal/utils/adjust-layout.js";
import { areArraysEqual, areNumbersAlmostEqual } from "$lib/internal/utils/compare.js";
import {
computePaneFlexBoxStyle,
getCursorStyle,
resetGlobalCursorStyle,
setGlobalCursorStyle,
} from "$lib/internal/utils/style.js";
import { assert } from "$lib/internal/utils/assert.js";
import { createContext } from "$lib/internal/utils/createContext.js";
import {
callPaneCallbacks,
findPaneDataIndex,
Expand All @@ -31,8 +22,17 @@ import {
paneDataHelper,
updateResizeHandleAriaValues,
validatePaneGroupLayout,
} from "./internal/helpers.js";
import { createContext } from "./internal/utils/createContext.js";
} from "$lib/internal/helpers.js";
import { isKeyDown, isMouseEvent, isTouchEvent } from "$lib/internal/utils/is.js";
import { adjustLayoutByDelta } from "$lib/internal/utils/adjust-layout.js";
import { areArraysEqual, areNumbersAlmostEqual } from "$lib/internal/utils/compare.js";
import {
computePaneFlexBoxStyle,
getCursorStyle,
resetGlobalCursorStyle,
setGlobalCursorStyle,
} from "$lib/internal/utils/style.js";
import { assert } from "$lib/internal/utils/assert.js";
import type {
Direction,
DragState,
Expand Down Expand Up @@ -233,7 +233,7 @@ class PaneGroupState {
// In this case, Pane sizes might not change–
// but updating cursor in this scenario would cause a flicker.
const prevDelta = this.prevDelta;
if (prevDelta != delta) {
if (prevDelta !== delta) {
this.prevDelta = delta;

if (!layoutChanged) {
Expand Down Expand Up @@ -823,10 +823,6 @@ class PaneState {
this.group.unregisterPane(this.paneData);
};
});

$effect(() => {
console.log("style", this.group.getPaneStyle(this.paneData, this.defaultSize.current));
});
}

props = $derived.by(() => ({
Expand Down
4 changes: 1 addition & 3 deletions sites/docs/src/lib/components/demos/collapsible-demo.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<script lang="ts">
import { Pane, PaneGroup, PaneResizer } from "paneforge";
import type { PaneAPI } from "paneforge";
import { DotsSixVertical } from "$icons/index.js";
import { Button } from "$lib/components/ui/button";
let paneOne = $state<PaneAPI>();
let paneOne = $state<Pane>();
let collapsed = $state(false);
</script>

Expand Down Expand Up @@ -35,7 +34,6 @@
collapsedSize={5}
collapsible={true}
minSize={15}
setPaneApi={(api) => (paneOne = api)}
onCollapse={() => (collapsed = true)}
onExpand={() => (collapsed = false)}
>
Expand Down

0 comments on commit 4149691

Please sign in to comment.