JSFiddle - React, Tailwind, and code Playground

by pj_js15

HTML

<script src="http://knockoutjs.com/downloads/knockout-2.2.1.debug.js"></script>
<script src="https://rawgithub.com/rniemeyer/knockout-sortable/master/build/knockout-sortable.js"></script>
<script src="http://one-com.github.io/knockout-dragdrop/vendor/knockout.dragdrop.js"></script>
<body>
        <div class="demo">
            
            <!-- orig code -->
            <!--
            <div class="dragElement" data-bind="with: dragElement">
               <div class="zones">
                    <ul class="source" data-bind="foreach: source, dropZone: { name: 'dragElement.target', drop: dropFromTarget }">
                        <li data-bind="text: $data, dragZone: { name: 'dragElement.source', element: 'dragElement' }"></li>
                    </ul>

                    <ul class="target" data-bind="foreach: target, dropZone: { name: 'dragElement.source', drop: dropFromSource }">
                        <li data-bind="text: $data, dragZone: { name: 'dragElement.target', element: 'dragElement' }"></li>
                    </ul>
                </div>
                <script type="text/html" id="dragElement">
                    <div class="customDragElement">Custom drag element: <span data-bind="text: $data"></span></div>
                </script>
            </div>
            -->
            
            <!-- test implementation using divs -->
            <div class="dragElement" data-bind="with: dragElement">
               <div class="zones">
                    <div class="source" data-bind="foreach: source, dropZone: { name: 'dragElement.target', drop: dropFromTarget }">
                        <div class="element" data-bind="text: $data, dragZone: { name: 'dragElement.source', element: 'dragElement' }"></div>
                    </div>

                    <div class="target" data-bind="foreach: target, dropZone: { name: 'dragElement.source', drop: dropFromSource }">
                        <div  class="element"  data-bind="text: $data, dragZone: { name:...

CSS

body {
        padding: 20px 60px;
    }
    .zones {
        height: 297px;
        position: relative;
    }
    
    .source {
        border: 1px solid grey;
        padding: 0;
        margin: 0;
        float: left;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        -webkit-user-select: none;
        -moz-user-select: -moz-none;
        -ms-user-select: none;
        -o-user-select: none;
        user-select: none;
        width: 150px;
        height: 200px;
    }
    
    .target {
        background-color: grey;
        border: 1px solid grey;
        padding: 0;
        margin: 0;
        margin-left: 10px;
        float: left;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        -webkit-user-select: none;
        -moz-user-select: -moz-none;
        -ms-user-select: none;
        -o-user-select: none;
        user-select: none;
        width: 150px;
        height: 200px;
    }
    .element
    {
        background-color: #FFF;
        border-bottom: 1px solid red;
    }
    
    ul {
        border: 1px solid grey;
        padding: 0;
        margin: 0;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        -webkit-user-select: none;
        -moz-user-select: -moz-none;
        -ms-user-select: none;
        -o-user-select: none;
        user-select: none;
    }
    ul.source {
        right: 51%;
    }
    ul.target {
        left: 51%;
    }
    ul.drag-over {
        -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(0, 0, 0, 0.8);
        -moz-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(0, 0, 0, 0.8);
        box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(0, 0, 0, 0.8);
    
        background-color: #F4FFDD;
        -moz-transition: all 300ms, -moz-transform;
        -webkit-transition: all 300ms, -webkit-transform;
        -o-transition: all 300ms, -o-transform;
        transition: all...

JavaScript

/*global $, ko*/
(function ($, ko) {
    function toDraggables(values) {
        return ko.utils.arrayMap(values, function (value) { 
            return {
                value: value,
                dragging: ko.observable(false)
            };
        });
    }

    var names = [
        'Declan',
        'Tessa',
        'Claire',
        'Violet',
        'Alice',
        'Mia',
        'Camille',
        'Aiden'
    ];

    var model = {
        dragElement: {
            source: ko.observableArray([].concat(names)),
            target: ko.observableArray(),
            dropFromSource: function (data, model) {
                model.source.remove(data);
                model.target.push(data);
            },
            dropFromTarget: function (data, model) {
                model.target.remove(data);
                model.source.push(data);
            }
        },

       rejectDrop: {
            source: ko.observableArray(toDraggables(names)),
            target: ko.observableArray(),
            dragStart: function (item) {
                item.dragging(true);
            },
            dragEnd: function (item) {
                item.dragging(false);
            },
            dragEnter: function (event, data, model) {
                var match = data.value.match(/^(a|e|i|o|u|y)/i);
                return !!match;
            },
            dropFromSource: function (data, model) {
                model.source.remove(data);
                model.target.push(data);
            },
            dropFromTarget: function (data, model) {
                model.target.remove(data);
                model.source.push(data);
            }
        },

        sortable: {
            items: ko.observableArray(toDraggables(names)),
            dragStart: function (item) {
                item.dragging(true);
            },
            dragEnd: function (item) {
                item.dragging(false);
            },
            reorder: function (event, dragData,...