@natachah/vanilla-frontend 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -48,23 +48,23 @@
|
|
|
48
48
|
</div>
|
|
49
49
|
|
|
50
50
|
<h2 id="handle">Handle</h2>
|
|
51
|
-
<p>You can decide which part of the item is draggable with the <code>data-handle</code> attribute</p>
|
|
51
|
+
<p>You can decide which part of the item is draggable with the <code>data-handle="sortable"</code> attribute</p>
|
|
52
52
|
<doc-demo>
|
|
53
53
|
<ul class="demo-sortable">
|
|
54
54
|
<li draggable=" false">
|
|
55
|
-
<span data-handle>
|
|
55
|
+
<span data-handle="sortable">
|
|
56
56
|
HANDLE
|
|
57
57
|
</span>
|
|
58
58
|
Lorem, ipsum.
|
|
59
59
|
</li>
|
|
60
60
|
<li draggable="false">
|
|
61
|
-
<span data-handle>
|
|
61
|
+
<span data-handle="sortable">
|
|
62
62
|
HANDLE
|
|
63
63
|
</span>
|
|
64
64
|
Impedit, quod!
|
|
65
65
|
</li>
|
|
66
66
|
<li draggable="false">
|
|
67
|
-
<span data-handle>
|
|
67
|
+
<span data-handle="sortable">
|
|
68
68
|
HANDLE
|
|
69
69
|
</span>
|
|
70
70
|
Repudiandae, rerum.
|
|
@@ -75,19 +75,19 @@
|
|
|
75
75
|
<doc-code>
|
|
76
76
|
<ul id="mySortableListWithHandle">
|
|
77
77
|
<li draggable="false">
|
|
78
|
-
<span data-handle>
|
|
78
|
+
<span data-handle="sortable">
|
|
79
79
|
Handle
|
|
80
80
|
</span>
|
|
81
81
|
Lorem, ipsum.
|
|
82
82
|
</li>
|
|
83
83
|
<li draggable="false">
|
|
84
|
-
<span data-handle>
|
|
84
|
+
<span data-handle="sortable">
|
|
85
85
|
Handle
|
|
86
86
|
</span>
|
|
87
87
|
Impedit, quod!
|
|
88
88
|
</li>
|
|
89
89
|
<li draggable="false">
|
|
90
|
-
<span data-handle>
|
|
90
|
+
<span data-handle="sortable">
|
|
91
91
|
Handle
|
|
92
92
|
</span>
|
|
93
93
|
Repudiandae, rerum.
|
|
@@ -135,9 +135,9 @@
|
|
|
135
135
|
<doc-code data-type="js">
|
|
136
136
|
const mySortable = document.getElementById('mySortableList')
|
|
137
137
|
mySortable.addEventListener('sortable:drag', (e) => {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
const theCollectionOfItems = e.detail.items
|
|
139
|
+
const thecurrentItem = e.detail.current
|
|
140
|
+
...
|
|
141
141
|
})
|
|
142
142
|
</doc-code>
|
|
143
143
|
|
|
@@ -136,12 +136,12 @@
|
|
|
136
136
|
</blockquote>
|
|
137
137
|
|
|
138
138
|
<h2>Handle</h2>
|
|
139
|
-
<p>You can decide which part of the item toggle the open/close method with the <code>data-handle</code> attribute</p>
|
|
139
|
+
<p>You can decide which part of the item toggle the open/close method with the <code>data-handle="tree"</code> attribute</p>
|
|
140
140
|
<doc-demo>
|
|
141
141
|
<ul class="demo-tree" role="tree">
|
|
142
142
|
<li role="treeitem">
|
|
143
143
|
<span aria-expanded="false" aria-owns="sublist">
|
|
144
|
-
<span data-handle>
|
|
144
|
+
<span data-handle="tree">
|
|
145
145
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
|
|
146
146
|
<path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"></path>
|
|
147
147
|
</svg>
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
...
|
|
163
163
|
<li role="treeitem">
|
|
164
164
|
<span aria-expanded="false" aria-owns="treelist">
|
|
165
|
-
<span data-handle>
|
|
165
|
+
<span data-handle="tree">
|
|
166
166
|
HANDLE
|
|
167
167
|
</span>
|
|
168
168
|
Inventore, perspiciatis
|
|
@@ -209,8 +209,8 @@
|
|
|
209
209
|
<doc-code data-type="js">
|
|
210
210
|
const myTree = document.getElementById('myTree')
|
|
211
211
|
myTree.addEventListener('tree:changed', (e) => {
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
const isOpen = e.detail.isOpen
|
|
213
|
+
...
|
|
214
214
|
})
|
|
215
215
|
</doc-code>
|
|
216
216
|
|
package/js/_sortable.js
CHANGED
|
@@ -27,9 +27,11 @@ export default class Sortable extends BaseComponent {
|
|
|
27
27
|
super(el, options, 'sortable')
|
|
28
28
|
|
|
29
29
|
// Define the properties
|
|
30
|
-
this._withHandle = this._element.querySelector('[data-handle]') ? true : false
|
|
30
|
+
this._withHandle = this._element.querySelector('[data-handle=sortable]') ? true : false
|
|
31
31
|
this._current = null
|
|
32
32
|
|
|
33
|
+
console.log(this)
|
|
34
|
+
|
|
33
35
|
// Init the event listener
|
|
34
36
|
this.#init()
|
|
35
37
|
|
|
@@ -49,7 +51,7 @@ export default class Sortable extends BaseComponent {
|
|
|
49
51
|
this.items.forEach((item) => {
|
|
50
52
|
|
|
51
53
|
// Toggle the [dragable] attribute
|
|
52
|
-
item.addEventListener('mousedown', (e) => { if (!this._withHandle || e.target.hasAttribute('data-handle')) item.draggable = true })
|
|
54
|
+
item.addEventListener('mousedown', (e) => { if (!this._withHandle || (e.target.hasAttribute('data-handle') && e.target.getAttribute('data-handle') === 'sortable')) item.draggable = true })
|
|
53
55
|
item.addEventListener('mouseup', () => item.draggable = false)
|
|
54
56
|
|
|
55
57
|
// Drag and drop events
|
package/js/_tree.js
CHANGED
|
@@ -28,7 +28,7 @@ export default class Tree extends BaseComponent {
|
|
|
28
28
|
// Define the properties
|
|
29
29
|
this._type = this._element.role == 'tree' ? 'list' : 'grid'
|
|
30
30
|
|
|
31
|
-
this._withHandle = this._element.querySelector('[data-handle]') ? true : false
|
|
31
|
+
this._withHandle = this._element.querySelector('[data-handle=tree]') ? true : false
|
|
32
32
|
|
|
33
33
|
this._items = this._element.querySelectorAll('[aria-expanded]')
|
|
34
34
|
|
|
@@ -45,7 +45,7 @@ export default class Tree extends BaseComponent {
|
|
|
45
45
|
#init() {
|
|
46
46
|
|
|
47
47
|
this._items.forEach(item => item.addEventListener('click', (e) => {
|
|
48
|
-
if (!this._withHandle || e.target.hasAttribute('data-handle')) {
|
|
48
|
+
if (!this._withHandle || (e.target.hasAttribute('data-handle') && e.target.getAttribute('data-handle') === 'tree')) {
|
|
49
49
|
e.stopPropagation()
|
|
50
50
|
this.toggle(item)
|
|
51
51
|
}
|
|
@@ -34,9 +34,9 @@ beforeAll(() => {
|
|
|
34
34
|
'<li draggable="false">Three</li>' +
|
|
35
35
|
'</ul>' +
|
|
36
36
|
'<table id="fakeTable">' +
|
|
37
|
-
'<tr draggable="false"><td data-handle>DRAG</td><td>One</td></tr>' +
|
|
38
|
-
'<tr draggable="false"><td data-handle>DRAG</td><td>Two</td></tr>' +
|
|
39
|
-
'<tr draggable="false"><td data-handle>DRAG</td><td>Three</td></tr>' +
|
|
37
|
+
'<tr draggable="false"><td data-handle="sortable">DRAG</td><td>One</td></tr>' +
|
|
38
|
+
'<tr draggable="false"><td data-handle="sortable">DRAG</td><td>Two</td></tr>' +
|
|
39
|
+
'<tr draggable="false"><td data-handle="sortable">DRAG</td><td>Three</td></tr>' +
|
|
40
40
|
'</table>'
|
|
41
41
|
|
|
42
42
|
fakeListSortable = new Sortable(document.getElementById('fakeList'))
|
|
@@ -70,7 +70,7 @@ describe('Mousedown & Mouseup', () => {
|
|
|
70
70
|
|
|
71
71
|
test('With handle & Mouseup toggle the [draggable] attribute', () => {
|
|
72
72
|
const item = document.querySelector('#fakeTable tr')
|
|
73
|
-
const handle = document.querySelector('#fakeTable tr:first-child [data-handle]')
|
|
73
|
+
const handle = document.querySelector('#fakeTable tr:first-child [data-handle=sortable]')
|
|
74
74
|
const customMousedown = new MouseEvent('mousedown')
|
|
75
75
|
Object.defineProperty(customMousedown, 'target', { value: handle }) // Define the mousedown event with custom target
|
|
76
76
|
expect(item.draggable).toBeFalsy()
|
package/js/tests/tree.test.js
CHANGED
|
@@ -41,8 +41,8 @@ beforeAll(() => {
|
|
|
41
41
|
'</ul>' +
|
|
42
42
|
'<table id="fakeGridTree" role="treegrid">' +
|
|
43
43
|
'<tr aria-level="1"><td></td></tr>' +
|
|
44
|
-
'<tr aria-level="1" aria-expanded="false" aria-owns="lvl2"><td data-handle></td></tr>' +
|
|
45
|
-
'<tr id="lvl2" aria-level="2" aria-expanded="false" aria-owns="lvl3" hidden><td data-handle></td></tr>' +
|
|
44
|
+
'<tr aria-level="1" aria-expanded="false" aria-owns="lvl2"><td data-handle="tree"></td></tr>' +
|
|
45
|
+
'<tr id="lvl2" aria-level="2" aria-expanded="false" aria-owns="lvl3" hidden><td data-handle="tree"></td></tr>' +
|
|
46
46
|
'<tr id="lvl3" aria-level="3" hidden><td></td></tr>' +
|
|
47
47
|
'<tr aria-level="1"><td></td></tr>' +
|
|
48
48
|
'</table>'
|
|
@@ -53,7 +53,7 @@ beforeAll(() => {
|
|
|
53
53
|
fakeRow = fakeGridTree._element.querySelector('tr[aria-level="1"][aria-expanded]')
|
|
54
54
|
|
|
55
55
|
customClick = new MouseEvent('click')
|
|
56
|
-
Object.defineProperty(customClick, 'target', { value: fakeRow.querySelector('[data-handle]') }) // Define the click event with custom target
|
|
56
|
+
Object.defineProperty(customClick, 'target', { value: fakeRow.querySelector('[data-handle=tree]') }) // Define the click event with custom target
|
|
57
57
|
|
|
58
58
|
})
|
|
59
59
|
|
|
@@ -130,10 +130,10 @@ describe('#Toggle()', () => {
|
|
|
130
130
|
const lvl3 = document.getElementById('lvl3')
|
|
131
131
|
|
|
132
132
|
const customClickLvl2 = new MouseEvent('click')
|
|
133
|
-
Object.defineProperty(customClickLvl2, 'target', { value: lvl2.querySelector('[data-handle]') }) // Define the click event with custom target
|
|
133
|
+
Object.defineProperty(customClickLvl2, 'target', { value: lvl2.querySelector('[data-handle=tree]') }) // Define the click event with custom target
|
|
134
134
|
|
|
135
135
|
const customClickLvl3 = new MouseEvent('click')
|
|
136
|
-
Object.defineProperty(customClickLvl3, 'target', { value: lvl3.querySelector('[data-handle]') }) // Define the click event with custom target
|
|
136
|
+
Object.defineProperty(customClickLvl3, 'target', { value: lvl3.querySelector('[data-handle=tree]') }) // Define the click event with custom target
|
|
137
137
|
|
|
138
138
|
fireEvent(fakeRow, customClick)
|
|
139
139
|
fireEvent(lvl2, customClickLvl2)
|