Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

EmberJS wrapper for the sortable library

License

NotificationsYou must be signed in to change notification settings

SortableJS/ember-sortablejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusEmber Observer Score

This addon allows you to use drag and drop in your ember application usingSortableJS/Sortable

Compatibility

  • Ember.js v3.13 or above
  • Ember CLI v3.13 or above
  • Node.js v10 or above

Installation

NOTE: The beta version is out. Please give me a hand and test it out.

ember install ember-sortablejs@beta

This addon has a peer dependency onsortablejs that will be installed with the addon

Still to do

Refer to the upcomingproject

Library support

Currently supported:

  • Drag from one list to another
  • Sort
  • Clone
  • Swap
  • Multi Drag
  • Nested List

Usage

{{!-- this.list = [{ name: 'item one' }, { name: 'item two' },..]  --}}<SortableJs  @items={{this.list}}  @options={{hashanimation=150ghostClass="ghost-class"group="shared-list"}}  @onStart={{this.onStart}}  @onEnd={{this.onEnd}}  as |list|>{{#eachlistas |item|}}    <divclass="list-group-item bg-yellow">{{item.value.name}}</div>{{/each}}</SortableJs>

How it works

SortableJs works by manipulating the DOM directly this is NOT compatible withthe Glimmer VM. To mitigate this we need tu use SortableJs as a middle man and usethe events it emits to update state and prevent the DOM manipulation the library does.

This is accomplished by maintaining an internal list. This list is a copy of thearray supplied via@items. The eventsonStart,onEnd,onUpdate,onAdd,onRemove are intercepted to prevent DOM manipulation and maintaining the internallist.

You HAVE to provide an object. As the addon uses a WeakMap to cache the items supplied.When SortableJs emits we update the list and the cache to make changes that will updatethe DOM. The addon willyield an array of objects. Each object contains the keyvalue,which is the original object supplied via@items.

I you have ideas on how to approach this better. Please open an issue 😄

Caveats

  • Not all SortableJS plugins work... yet.
  • While you could bypass@items I highly discourage since the library manipulates the DOM directly.

Options

The addon supports all the options that sortable accepts, see:https://github.com/SortableJS/Sortable#options

Component API

argtypedescription
@itemsArrayA list of objecs to be managed by the addon
@optionsObjectA hash options supported by SortableJs
@tagStringThe element to be used to render the list (default: "div")
@onChooseFunction(SortablejsEvent) => {...}
@onUnchooseFunction(SortablejsEvent) => {...}
@onStartFunction(SortablejsEvent) => {...}
@onEndFunction(SortablejsEvent, cancelDnD) => {...}
@onAddFunction(SortablejsEvent) => {...}
@onUpdateFunction(SortablejsEvent) => {...}
@onSortFunction(SortablejsEvent) => {...}
@onRemoveFunction(SortablejsEvent) => {...}
@onMoveFunction(SortablejsMoveEvent) => {...}
@onCloneFunction(SortablejsEvent) => {...}
@onChangeFunction(SortablejsEvent) => {...}
@scrollFnFunction(SortablejsEvent) => {...}
@setDataFunction(SortablejsEvent) => {...}
@onFilterFunction(SortablejsEvent) => {...}
@onSpillFunction(SortablejsEvent) => {...}

SortablejsEvent - ACustomEvent provided by SortableJS

SortablejsMoveEvent - ACustomEvent provided by SortableJS

cancelDnD - A callback provided by the ember addon to basically undo you last drag and drop or sort;

{{yield}} - An array of objects with the keyvalue where its value is the object supplied.{ value: <Object> }

Migrating from 1.x

  • onSetData is no longer suported. Rename argument tosetData.
  • <SortableJs> no longer expects a wrapped list. Instead the addon itself will act as the sortable list container.

v1

<SortableJs  @options={{hashanimation=150ghostClass="ghost-class"group="shared-list"}}>  <ulclass="list-group">    <liclass="list-group-item">Item 1</li>    <liclass="list-group-item">Item 2</li>    <liclass="list-group-item">Item 3</li>    <liclass="list-group-item">Item 4</li>    <liclass="list-group-item">Item 5</li>  </ul></SortableJs>

v2

{{!-- this.list = [{ name: 'item one' }, { name: 'item two' },..]  --}}<SortableJsclass="list-group"  @items={{this.list}}  @options={{hashanimation=150ghostClass="ghost-class"group="shared-list"}}  as |list|>{{#eachlistas |item|}}    <divclass="list-group-item">{{item.value.name}}</div>{{/each}}</SortableJs>

License

This project is licensed under theGPL-3.0 License.

About

EmberJS wrapper for the sortable library

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp