Giter Site home page Giter Site logo

Comments (3)

frankykubo avatar frankykubo commented on September 17, 2024 1

Its better to use index.d.ts approach since you don't have to change existing files if you do not want. But even if you implement new .ts files, I think it would be better to create index.d.ts file.

from vue-dndrop.

CultivateCreate avatar CultivateCreate commented on September 17, 2024

Hi everyone, I currently use this library in a project and I would like to contribute by adding typescript support. Do you want me to work on this? If yes, would it rather be by replacing every .js with .ts or by adding an index.d.ts?

Thanks for your repository.

This would be very helpful. The library seems more intuitive than others I've found and my projects are in TS.

from vue-dndrop.

thetobber avatar thetobber commented on September 17, 2024

I created @types/vue-dndrop/index.d.ts in the src directory of my project.

/// <reference types='vue' />

declare module 'vue-dndrop' {
  import type {
    AllowedComponentProps,
    ComponentCustomProps,
    ComponentOptionsMixin,
    DefineComponent,
    NativeElements,
    PropType,
    VNodeProps,
  } from 'vue'

  type WithTemplateSlots<T, S> = T & {
    new (): {
      $slots: S
    }
  }

  export type DragResult = {
    isSource: boolean
    payload: unknown
    willAcceptDrop: boolean
  }

  export type DropResult = {
    addedIndex: number | null
    element: HTMLElement
    payload: unknown
    removedIndex: number | null
  }

  export type DropNotAllowedResult = {
    payload: unknown
    container: object
  }

  export type Tag =
    | keyof NativeElements
    | { [K in keyof NativeElements]: { value: K; props: NativeElements[K] } }[keyof NativeElements]

  export type ContainerProps = {
    orientation?: 'horizontal' | 'vertical'
    behaviour?: 'move' | 'copy' | 'drop-zone' | 'contain'
    tag?: Tag
    groupName?: string
    lockAxis?: 'x' | 'y'
    dragHandleSelector?: string
    nonDragAreaSelector?: string
    dragBeginDelay?: number
    animationDuration?: number
    autoScrollEnabled?: boolean
    dragClass?: string
    dropClass?: string
    removeOnDropOut?: boolean
    dropPlaceholder?: boolean | Record<string, any>
    fireRelatedEventsOnly?: boolean
    getChildPayload?: (index: number) => unknown
    shouldAcceptDrop?: (sourceContainerOptions: object, payload: unknown) => boolean
    shouldAnimateDrop?: (sourceContainerOptions: object, payload: unknown) => boolean
    getGhostParent?: () => HTMLElement
  }

  export type ContainerEmits = {
    dragStart?: (dragResult: DragResult) => void
    dragEnd?: (dragResult: DragResult) => void
    dragEnter?: () => void
    dragLeave?: () => void
    dropReady?: (dropResult: DropResult) => void
    drop?: (dropResult: DropResult) => void
    dropNotAllowed?: (dropNotAllowedResult: DropNotAllowedResult) => void
  }

  export const Container: WithTemplateSlots<
    DefineComponent<
      { [K in keyof ContainerProps]-?: { type: PropType<ContainerProps[K]> } },
      {},
      unknown,
      {},
      {},
      ComponentOptionsMixin,
      ComponentOptionsMixin,
      ContainerEmits,
      string,
      VNodeProps & AllowedComponentProps & ComponentCustomProps,
      Readonly<ContainerProps> & { [K in keyof ContainerEmits as `on${Capitalize<K>}`]?: ContainerEmits[K] },
      {},
      {}
    >,
    Readonly<{ default(): any }>
  >

  export type DraggableProps = {
    dragNotAllowed?: boolean
    tag?: Tag
  }

  export const Draggable: WithTemplateSlots<
    DefineComponent<
      { [K in keyof DraggableProps]-?: { type: PropType<DraggableProps[K]> } },
      {},
      unknown,
      {},
      {},
      ComponentOptionsMixin,
      ComponentOptionsMixin,
      {},
      string,
      VNodeProps & AllowedComponentProps & ComponentCustomProps,
      Readonly<DraggableProps>,
      {},
      {}
    >,
    Readonly<{ default(): any }>
  >
}

from vue-dndrop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.