4 |
5 |
6 |
7 |
8 | drag-drop-kanban
9 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/src/wrapper.js:
--------------------------------------------------------------------------------
1 | /* istanbul ignore file */
2 | // Import vue component
3 | import VueDragNDrop from './vue-drag-n-drop.vue';
4 |
5 | // Declare install function executed by Vue.use()
6 | export function install(Vue) {
7 | if (install.installed) return;
8 | install.installed = true;
9 | Vue.component('vue-drag-n-drop', VueDragNDrop);
10 | }
11 |
12 | // Create module definition for Vue.use()
13 | const plugin = {
14 | install,
15 | };
16 |
17 | // Auto-install when vue is found (eg. in browser via
24 |
25 |
48 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: BUG
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: npm-publish
2 | on:
3 | push:
4 | branches:
5 | - master # Change this to your default branch
6 | jobs:
7 | npm-publish:
8 | name: npm-publish
9 | runs-on: ubuntu-latest
10 | steps:
11 | - name: Checkout repository
12 | uses: actions/checkout@master
13 | - name: Set up Node.js
14 | uses: actions/setup-node@master
15 | with:
16 | node-version: 10.0.0
17 | - name: Installing all the packages
18 | run: yarn install
19 | - name: Building the module...
20 | run: yarn build
21 | - name: Publish if version has been updated
22 | uses: pascalgn/npm-publish-action@4f4bf159e299f65d21cd1cbd96fc5d53228036df
23 | with: # All of theses inputs are optional
24 | tag_name: "v%s"
25 | tag_message: "v%s"
26 | commit_pattern: "^Release (\\S+)"
27 | env: # More info about the environment variables in the README
28 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Leave this as is, it's automatically generated
29 | NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # You need to set this in your repo settings
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Sujil Maharjan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.github/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 |
2 | # Contributor Code of Conduct
3 |
4 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
5 |
6 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
7 |
8 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
9 |
10 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
11 |
12 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
13 |
14 | This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at https://www.contributor-covenant.org/version/1/0/0/code-of-conduct.html
15 |
--------------------------------------------------------------------------------
/src/drag-n-drop-props.js:
--------------------------------------------------------------------------------
1 | /* istanbul ignore file */
2 | export default {
3 | /**
4 | * Holds the main data list to distribute.
5 | */
6 | originalData: {
7 | type: Array,
8 | required: true,
9 | },
10 |
11 | /**
12 | * Holds the drop buckets.
13 | */
14 | dropzones: {
15 | type: Array,
16 | required: true,
17 | },
18 |
19 | /**
20 | * Title for the original list.
21 | */
22 | originalTitle: {
23 | type: String,
24 | required: false,
25 | default: "Original List",
26 | },
27 |
28 | /**
29 | * Title for the drop buckets.
30 | */
31 | dropzonesTitle: {
32 | type: String,
33 | required: false,
34 | default: "Distribution data",
35 | },
36 |
37 | /**
38 | * An option to have an in-place changes. So, the props passed into the component itself would change.
39 | * If true, all the drags and drops done in this component is reflected in parent's objects.
40 | * If false, you need to have save button to get all the changes to the parent component.
41 | */
42 | inPlace: {
43 | type: Boolean,
44 | required: false,
45 | default: true,
46 | },
47 |
48 | /**
49 | * Enables save button
50 | */
51 | enableSave: {
52 | type: Boolean,
53 | required: false,
54 | default: true,
55 | },
56 |
57 | /**
58 | * Enables cancel button
59 | */
60 | enableCancel: {
61 | type: Boolean,
62 | required: false,
63 | default: true,
64 | },
65 | };
66 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vue-drag-n-drop",
3 | "version": "1.3.0",
4 | "private": false,
5 | "description": "A simple kanban board where the items can be dragged and dropped from the list. This is a hybrid implementation of vue-smooth-dnd.",
6 | "scripts": {
7 | "serve": "vue-cli-service serve",
8 | "build": "npm run build:umd & npm run build:es & npm run build:unpkg",
9 | "test": "vue-cli-service test:unit",
10 | "build:es": "rollup --config build/rollup.config.js --format es --file dist/vue-drag-n-drop.esm.js",
11 | "build:umd": "rollup --config build/rollup.config.js --format umd --file dist/vue-drag-n-drop.umd.js",
12 | "build:unpkg": "rollup --config build/rollup.config.js --format iife --file dist/vue-drag-n-drop.min.js"
13 | },
14 | "main": "dist/vue-drag-n-drop.umd.js",
15 | "module": "dist/vue-drag-n-drop.esm.js",
16 | "browser": {
17 | "./sfc": "src/vue-drag-n-drop.vue"
18 | },
19 | "unpkg": "dist/vue-drag-n-drop.min.js",
20 | "files": [
21 | "dist/*"
22 | ],
23 | "husky": {
24 | "hooks": {
25 | "pre-commit": "npm test"
26 | }
27 | },
28 | "dependencies": {
29 | "lodash": "^4.17.13",
30 | "vue-smooth-dnd": "^0.2.1"
31 | },
32 | "devDependencies": {
33 | "@vue/cli-plugin-babel": "~4.2.0",
34 | "@vue/cli-plugin-unit-jest": "~4.3.0",
35 | "@vue/cli-service": "~4.2.0",
36 | "@vue/test-utils": "1.0.0-beta.31",
37 | "rollup": "^1.17.0",
38 | "rollup-plugin-buble": "^0.19.8",
39 | "rollup-plugin-commonjs": "^10.0.1",
40 | "rollup-plugin-vue": "^5.0.1",
41 | "sinon": "^9.0.1",
42 | "vue": "^2.6.11",
43 | "vue-template-compiler": "^2.6.11"
44 | },
45 | "bugs": {
46 | "url": "https://github.com/smaharj1/vue-drag-and-drop-kanban/issues"
47 | },
48 | "contributors": [
49 | {
50 | "name": "Sujil Maharjan",
51 | "url": "https://github.com/smaharj1"
52 | }
53 | ],
54 | "keywords": [
55 | "Vue",
56 | "Vue.js",
57 | "sortable",
58 | "drag and drop",
59 | "drag&drop",
60 | "drag",
61 | "drop",
62 | "draggable",
63 | "dnd",
64 | "kanban",
65 | "smooth-dnd"
66 | ],
67 | "license": "MIT",
68 | "repository": {
69 | "type": "git",
70 | "url": "https://github.com/smaharj1/vue-drag-and-drop-kanban"
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/tests/unit/vue-drag-n-drop.spec.js:
--------------------------------------------------------------------------------
1 | import { shallowMount } from '@vue/test-utils'
2 | import DragDrop from '@/vue-drag-n-drop.vue'
3 | import _ from 'lodash';
4 |
5 | jest.mock('lodash')
6 |
7 | describe('vue-drag-n-drop.vue', () => {
8 | let props, wrapper;
9 | beforeEach(() => {
10 | props = {
11 | originalData: [
12 | 'item1',
13 | 'item2',
14 | 'item3'
15 | ],
16 | inPlace: false,
17 | dropzones: [
18 | {
19 | name: 'Zone1',
20 | children: [
21 | 'zchild1',
22 | 'zchild2'
23 | ]
24 | },
25 | {
26 | name: 'Zone2',
27 | children: []
28 | },
29 | {
30 | name: 'Zone3',
31 | children: []
32 | }
33 | ]
34 | };
35 |
36 | wrapper = shallowMount(DragDrop, {
37 | propsData: props,
38 | });
39 | });
40 |
41 | // Checks if the component renders.
42 | it('renders the component', () => {
43 | expect(wrapper.contains('div')).toBe(true);
44 | });
45 |
46 | it('provides default original list title if prop is not provided', () => {
47 | expect(wrapper.props().originalTitle).toEqual('Original List');
48 | });
49 |
50 | it('provides default dropzone title if not in props', () => {
51 | expect(wrapper.props().dropzonesTitle).toEqual('Distribution data');
52 | });
53 |
54 | it('deep clones the dropzones when inplace is false', () => {
55 | expect(_.cloneDeep).toHaveBeenCalledWith(wrapper.props().dropzones);
56 | });
57 |
58 | it('runs the validation of original list and emits save event on valid data on save click', () => {
59 | wrapper.find('button.dd-save').trigger('click');
60 |
61 | expect(wrapper.emitted().save).toBeTruthy();
62 | });
63 |
64 | it('emits cancel when cancel button is clicked', () => {
65 | wrapper.find('button.dd-cancel').trigger('click');
66 | expect(wrapper.emitted().cancel).toBeTruthy();
67 | });
68 |
69 | it('gets the card payload when the card payload is requested', () => {
70 | wrapper.setData({
71 | dropGroups: [
72 | {
73 | name: 'Zone1',
74 | children: [
75 | 'zchild1',
76 | 'zchild2'
77 | ]
78 | }
79 | ]
80 | })
81 | const resp = wrapper.vm.getCardPayload('Zone1');
82 | expect(resp(0)).toEqual('zchild1');
83 | });
84 |
85 |
86 |
87 | })
88 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | All notable changes to this project will be documented in this file.
3 |
4 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6 |
7 | ## [1.2.2]
8 |
9 | ### Changed
10 |
11 | - Added documentation on SSR/Nuxt
12 | ## [1.2.1]
13 | ### Changed
14 | - Modified the button design
15 | - Fixed the security vulnerabilities
16 |
17 | ## [1.2.0]
18 | ### Added
19 | - Added couple of new event emitters `dropInOriginalBucket` and `dropInDestinationBucket`.
20 | - Added more documentation for events in the README.
21 |
22 | ## [1.1.0]
23 | ### Changed
24 | - Changed the css class name to be more specific to the component
25 | - Changed the css value to make the cards not tilt
26 | - Changed the original container to scroll vertically rather than horizontally.
27 | - Bug fix: When everything from original bucket was moved to dropzones, original used to collapse. Now, it doesnt and the user can move the cards back to original.
28 |
29 | ## [1.0.0](https://github.com/smaharj1/vue-drag-and-drop-kanban/releases/tag/v1.0.0) - 2020-04-10
30 | ### Added
31 | - Added new props
32 | - **inPlace**: makes in place changes to props dropzones. Enabled by default
33 | - **enableSave**: Enable Save button
34 | - **enableCancel**: Enable Cancel button
35 | - Changelog.md file added
36 |
37 | ### Changed
38 | - Introduced vue slots for the content of each card. Users can have their own card components
39 | - Enabling list of objects to be passed rather than string. Also, works for string. The change will not break previous version.
40 | - `save` event's response body has changed to reflect the items in original list and dropzones when save pressed.
41 | - Modified documentation
42 |
43 | ### Removed
44 | - Removed the logic for validation. Parent components can handle this during `save`
45 |
46 | ---
47 |
48 | ## [0.0.16](https://github.com/smaharj1/vue-drag-and-drop-kanban/releases/tag/v0.0.16) - 2020-04-06
49 | ### Added
50 | - Added more documentation
51 | - Code of Conduct
52 | - Template for creating pull request
53 | - Templates for raising an issue
54 | - Update on Readme.md to include more details on installation and usage
55 |
56 | - Added Test Framework
57 | - Added Jest test for the component
58 | - Tests generate code coverage report
59 | - Added test cases. Current coverage about ~52%.
60 |
61 | - Husky implementation
62 | - Added husky so that the test is ran every time devs try to push to improve code quality
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | All the cards displayed below are Vue Slots and can be totally customized to be any way
5 |
6 |
7 |
12 |
13 | A simple kanban board where the items can be dragged and dropped from the list. This is a hybrid implementation of vue-smooth-dnd.
14 |
15 | ## Demo
16 | 
17 |
18 | ## Usage
19 |
20 | #### Installation
21 | To use the vue-drag-n-drop module, you first need to install the module.
22 |
23 | ```
24 | npm install vue-drag-n-drop
25 | ```
26 | or
27 | ```
28 | yarn add vue-drag-n-drop
29 | ```
30 |
31 | #### Use Case
32 |
33 | ``` html
34 |
35 |
129 |
130 |
131 |
142 | ```
143 |
144 | ## Documentation
145 | #### Instantiating the component
146 | To put the component in your code, you can simply run `import DragDrop from 'vue-drag-n-drop';`. Then, use it in the code as:
147 |
148 | ```html
149 |
155 | ```
156 |
157 | `originalData` in the above code is assumed to be a list of string. However, you can also pass in the list of custom objects like this:
158 |
159 | ```js
160 | [
161 | {
162 | title: 'Strategy 101',
163 | description: 'Create a draft of business plan',
164 | time: '3 days',
165 | done: false
166 | },
167 | {
168 | title: 'Strategy 102',
169 | description: 'Finalize the plan',
170 | time: '4 days',
171 | done: false
172 | }
173 | ]
174 | ```
175 |
176 | When you pass your own objects instead of a list of string, you also need to provide a custom component to handle view/action of this object since you can virtually pass any kind of object.
177 |
178 | #### Events
179 | When you use the component, you can also listen to some events that happen inside the component like drag, drop, save and cancel
180 |
181 | ```html
182 |
192 | ```
193 |
194 | `save` - This event is triggered when you click save from inside the component. It gives back the final state of the data in corresponding buckets.
195 |
196 | `cancel` - This gives you a choice on how to handle the cancellationn event.
197 |
198 | `dropInOriginalBucket` - This event is emitted everytime there is a drop event for original bucket. You provides an object with `startIndex`, `endIndex` and `payload`.
199 |
200 | `dropInDestinationBucket` - This event is emitted for each dropzone in the destination bucket. First parameter returns the dropzone name and second parameter returns the drop info `startIndex`, `endIndex` and `payload`.
201 |
202 | #### Custom Component for list of objects
203 | `vue-drag-n-drop` uses Vue Named Slots. So, the users can pass in custom component that will have access to the data for the single item. You can impolement the slots like below:
204 |
205 | ```html
206 |
212 |
213 |
217 |
218 |
219 | ```
220 |
221 | Here, `dd-card` is the slot name. The component provides a `cardData` variable provides the access of a single object from the original data. If slots aren't used, the component assumes that original data is a list of string. This makes it compatible with older version.
222 |
223 |
224 | #### CSS Modification
225 |
226 | To modify the CSS style, you can override these css classes from your component:
227 |
228 | ```
229 | .vue-drag-n-drop # This holds the whole container.
230 |
231 | .dd-title # Class for modifying the titles
232 |
233 | .dd-first-group # Class to modify the first (original) container. It holds the list of
234 | cards
235 |
236 | .dd-card-ghost # Class provided for drag class by smooth-dnd
237 |
238 | .dd-card-ghost-drop # Class provided for drop by smooth-dnd
239 |
240 | .dd-result-group # Class to modify the second drop container (Result container)
241 |
242 | .dd-drop-container # Class to modify the style of each column for second container
243 |
244 | ```
245 |
246 | ## Support for SSR/Nuxt
247 | Currently, Server Side Rendering is **not** supported. To use it in SSR/Nuxt project, you need to specify Nuxt that this plugin needs to render on the client side.
248 |
249 | To specify Nuxt to render it on client-side, create a JS file under `~/plugins/` or add to existing one:
250 |
251 | `~/plugins/vue-drap-n-drop.js`
252 | ```
253 | import Vue from 'vue';
254 | import DragDrop from 'vue-drag-n-drop';
255 |
256 | Vue.use(DragDrop);
257 | ```
258 |
259 | Add the plugin to `nuxt.config.js`
260 | ```
261 | plugins: [
262 | {
263 | src: './plugins/vue-drag-n-drop.js',
264 | ssr: false
265 | }
266 | ],
267 | ```
268 | ## Contributions
269 | Feel free to raise an issue or create a Pull Request if you see ways that can improve this library.
270 |
271 | ## Current Contributors
272 | [](https://sourcerer.io/fame/smaharj1/smaharj1/vue-drag-and-drop-kanban/links/0)[](https://sourcerer.io/fame/smaharj1/smaharj1/vue-drag-and-drop-kanban/links/1)[](https://sourcerer.io/fame/smaharj1/smaharj1/vue-drag-and-drop-kanban/links/2)[](https://sourcerer.io/fame/smaharj1/smaharj1/vue-drag-and-drop-kanban/links/3)[](https://sourcerer.io/fame/smaharj1/smaharj1/vue-drag-and-drop-kanban/links/4)[](https://sourcerer.io/fame/smaharj1/smaharj1/vue-drag-and-drop-kanban/links/5)[](https://sourcerer.io/fame/smaharj1/smaharj1/vue-drag-and-drop-kanban/links/6)[](https://sourcerer.io/fame/smaharj1/smaharj1/vue-drag-and-drop-kanban/links/7)
273 |
274 | ## License
275 | [MIT](https://opensource.org/licenses/MIT)
276 |
277 |
--------------------------------------------------------------------------------