패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.0.1

dnd

마우스 및 터치 지원을 갖춘 Dart 웹 앱용 드래그 앤 드롭.

Web
30일 다운로드
3.7만
좋아요
53
Pub 점수
130

패키지 설치

flutter pub add dnd

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

dnd 패키지는 마우스 및 터치 상호작용을 모두 지원하는 Dart 웹 애플리케이션에서 드래그 앤 드롭 기능을 가능하게 합니다. 화면 내 요소를 드래그하여 놓을 수 있는 직관적인 사용자 인터페이스를 구현하기 위한 가볍고 유연한 솔루션을 제공합니다. 인터랙티브 레이아웃, 정렬 가능한 목록 또는 파일 업로드 영역을 만들기에 적합하며, Flutter 웹 프로젝트와 원활하게 통합됩니다. 이 패키지는 오픈소스이며 marcojakob에 의해 유지 관리되며, 개발자들이 복잡한 커스텀 구현 없이 웹 앱의 상호작용을 쉽게 향상시킬 수 있도록 도와줍니다.

사용 사례

  • 정렬 가능한 목록
  • 파일 업로드 인터페이스
  • 인터랙티브 대시보드 위젯
  • 드래그 가능한 컴포넌트 재정렬
  • 웹 기반 칸반 보드
  • 사용자 정의 드래그 앤 드롭 양식

주요 기능

  • 마우스 및 터치 지원
  • 경량이며 통합이 쉬움
  • 크로스 브라우저 호환성
  • 이벤트 기반 API
  • 여러 개의 드래그 가능한 항목을 지원
  • 클린하고 미니멀한 디자인

적합한 대상

  • Flutter를 사용하는 웹 개발자
  • 인터랙티브 UI 컴포넌트가 필요한 앱
  • 드래그 앤 드롭 워크플로우를 가진 프로젝트
  • 인터랙티브 레이아웃 프로토타이핑
  • 교육 또는 생산성 웹 앱

고려 사항

  • 웹 플랫폼에만 제한됨
  • 네이티브 모바일 지원 없음
  • 수동 상태 관리가 필요합니다
  • 고주파 드래그 이벤트에 최적화되지 않음
  • 시각적 피드백을 위해 추가적인 스타일링이 필요할 수 있습니다
  • 외부 GitHub 저장소에 의존

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Dart Drag and Drop

Drag and Drop for Dart web apps with mouse and touch support.

Star this Repo Pub Package

GitHub | Pub | Demos and Examples

DnD Screenshot

Features

  • Use any HTML Element as Draggable or Dropzone.
  • Mouse and Touch dragging.
  • Draggable events: dragStart, drag, and dragEnd
  • Dropzone events: dragEnter, dragOver, dragLeave, and drop
  • Drag avatars as visual indication of a drag operation:
    • Original element as drag avatar.
    • Clone as drag avatar.
    • Custom drag avatar.
  • Support for Shadow DOM (Web Components, Custom Elements, Polymer, etc.).
  • Much more... see examples.

Usage

Before you read the instructions below, you should take a look at the examples.

Basic Set Up

Create a Draggable and give it some HTML elements; this will make them draggable. You can either pass a single Element to the constructor or an ElementList that is returned by querySelectorAll.

If you also want to drop somewhere, you'll need a Dropzone.

// Install draggable (no avatar).
Draggable draggable = Draggable(querySelectorAll('.draggable'));

// Install dropzone.
Dropzone dropzone = Dropzone(querySelector('.dropzone'));

You'll most likely want some drag avatar to show the user that a drag is going on. There are two predefined AvatarHandlers that you can use as follows. But you could also provide your own implementation of AvatarHandler.

// Draggable with clone as avatar.
Draggable draggable = Draggable(querySelectorAll('.draggable'),
    avatarHandler: AvatarHandler.clone());


// Draggable with original element as avatar.
Draggable draggable = Draggable(querySelectorAll('.draggable'),
    avatarHandler: AvatarHandler.original());
Draggable Options

The following options can be passed as named parameters to the constructor of Draggable:

  • avatarHandler: Is responsible for creating, position, and removing a drag avatar. A drag avatar provides visual feedback during a drag operation. Here are possible options (see above for an example):

    • null (the default) - will not create a drag avatar
    • AvatarHandler.original() - handler that uses the original draggable as avatar. See OriginalAvatarHandler.
    • AvatarHandler.clone() - handler that uses a clone of the draggable element as avatar. See CloneAvatarHandler.
    • A custom AvatarHandler - you can provide your own implementation of AvatarHandler.
  • horizontalOnly: If set to true, only horizontal dragging is tracked. This enables vertical touch dragging to be used for scrolling.

  • verticalOnly: If set to true, only vertical dragging is tracked. This enables horizontal touch dragging to be used for scrolling.

  • handle: If handle query String is specified, it restricts the dragging from starting unless it occurs on the specified element(s). Only elements that descend from the draggables elements are permitted.

  • cancel: If cancel query String is specified, drag starting is prevented on specified elements.

  • draggingClass: Is the css class set to the dragged element during a drag. If set to null, no such css class is added.

  • draggingClassBody: Is the css class set to the html body tag during a drag. If set to null, no such css class is added.

  • minDragStartDistance: Is the minimum distance in pixels that is needed for a drag to start. Default is 4. This allows for clicks with tiny movement.

Draggable Events

Available event Streams on Draggable:

  • onDragStart: Fired when the user starts dragging.
    Note: onDragStart is fired not on touchStart or mouseDown but as soon as there is a drag movement. When a drag is started an onDrag event will also be fired.

  • onDrag: Fired periodically throughout the drag operation.

  • onDragEnd: Fired when the user ends the dragging.
    Note: Is also fired when the user clicks the 'esc'-key or the window loses focus.

Dropzone Options

The following options can be passed as named parameters to the constructor of Dropzone:

  • acceptor: Is used to determine which Draggables will be accepted by this Dropzone. If none is specified, all Draggables will be accepted.

  • overClass: Is the css class set to the dropzone element when an accepted draggable is dragged over it. If set to null, no such css class is added.

  • invalidClass: Is the css class set to the dropzone element when a not-accepted draggable is dragged over it. If set to null, no such css class is added.

Dropzone Events

Available event Streams on Dropzone:

  • onDragEnter: Fired when a Draggable enters this Dropzone.

  • onDragOver: Fired periodically while a Draggable is moved over a Dropzone.

  • onDragLeave: Fired when a Draggable leaves this Dropzone.

  • onDrop: Fired when a Draggable is dropped inside this Dropzone.

Note: Dropzone events are only fired when the Draggable is accepted by the Acceptor.

Shadow DOM

Web Components create a nice ecapsulation through Shadow DOM. But this creates a problem with dropzones inside the Shadow DOM as they never receive events because all events are captured by the host element. To make this work we need to retarget events to the Shadow DOM children through recursive elementFromPoint() calls.

For performance reasons it wouldn't make sense to retarget all drag and drop events. If you wish to retarget events to the Shadow DOM children, you must add a dnd-retarget attribute to the host:

// Retarget drag and drop events to Shadow DOM children.
<my-element dnd-retarget></my-element>

Attribution

The Dart Drag and Drop library is inspired by

Thank you for your work!

Running / Building / Testing

  • Run from the terminal: webdev serve
  • Build from the terminal: webdev build

License

The MIT License (MIT)

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.