svelte-splitpanes Documentation

repository·master·Indexed 19 days ago

https://github.com/orefalo/svelte-splitpanes

A full featured resizable pane layout splitter for Svelte, ported from vue-splitpanes. Provides Splitpanes and Pane components, along with interfaces such as IPane, ClientCallbacks, IPaneSizingEvent, and SplitContext for managing layout state and pane interactions.

Tokens
1.4K
Snippets
8
Records
8
Agent score
17%

What's inside svelte-splitpanes

  1. Develop and run the Svelte development server

    master

    After creating your project and installing dependencies via npm install, pnpm install, or yarn, use the dev script to start the development server. You can use the --open flag to automatically open the application in a new browser tab.

    npm run dev
    
    # or start the server and open the app in a new browser tab
    npm run dev -- --open
  2. Build and preview the production application

    master

    To generate a production-ready version of your application, run the build script. Once built, you can use the preview script to test the production build locally. Note that deploying to specific environments may require installing a SvelteKit adapter.

    npm run build
    
    # preview the production build
    npm run preview
  3. Create a new Svelte project

    master

    Use npm create svelte@latest to scaffold a new Svelte project. You can either initialize the project in the current directory or specify a directory name.

    # create a new project in the current directory
    npm create svelte@latest
    
    # create a new project in my-app
    npm create svelte@latest my-app
  4. Use Splitpanes and Pane components

    master

    The primary way to use this library is by importing the Splitpanes and Pane components. Splitpanes acts as the container for multiple Pane components, allowing for resizable layouts.

    <script>
      import { Splitpanes, Pane } from 'svelte-splitpanes';
    </script>
    
    <Splitpanes>
      <Pane>Pane 1</Pane>
      <Pane>Pane 2</Pane>
    </Splitpanes>
  5. Reference the IPane interface

    master

    The IPane interface defines the internal structure and capabilities of a pane within the splitpane system. It includes properties for tracking size, constraints, and DOM elements.

    export interface IPane {
      // unique key per pane
      key: any;
      element: HTMLElement;
      // 0....N index in pane array
      index: number;
      min: () => number;
      max: () => number;
      snap: () => number;
      sz: () => number;
      setSz: (number: number) => void;
      setSplitterActive: (isActive: boolean) => void;
      givenSize: number | null;
      isReady: boolean;
    }
  6. Reference the IPaneSizingEvent interface

    master

    The IPaneSizingEvent interface describes the sizing details emitted during a sizing event, expressed in percentages.

    export interface IPaneSizingEvent {
      /**
       * Minimum size in %.
       */
      min: number;
    
      /**
       * Maximum size in %.
       */
      max: number;
    
      /**
       * Pane size in %.
       */
      size: number;
    
      /**
       * Snap size in %.
       */
      snap: number;
    }
  7. Reference the ClientCallbacks interface

    master

    The ClientCallbacks interface defines the event handlers provided to panes to react to user interactions with splitters and panes.

    export interface ClientCallbacks {
      onSplitterDown: (_event: TouchEvent | MouseEvent) => void;
      onSplitterClick: (_event: MouseEvent) => void;
      onSplitterDblClick: (_event: MouseEvent) => void;
      onPaneClick: (_event: MouseEvent) => void;
      /** Report the manual given size was changed. */
      reportGivenSizeChange: (_newGivenSize: number) => void;
    }
  8. Reference the SplitContext interface

    master

    The SplitContext interface represents the context passed from the Splitpanes container to its child Pane components. It provides reactive information about the layout state and methods for pane initialization and lifecycle management.

    export interface SplitContext {
      /** Tells the key of the very first pane, or undefined if not recieved yet. */
      veryFirstPaneKey: Readable<any>;
      isHorizontal: Readable<boolean>;
      showFirstSplitter: Readable<boolean>;
      ssrRegisterPaneSize?: (size: number | null) => void;
      onPaneInit: PaneInitFunction;
      clientOnly?: {
        onPaneAdd: (pane: IPane) => ClientCallbacks;
        onPaneRemove: (key: any) => Promise<void>;
      };
    }