-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathindex.js
101 lines (85 loc) · 2.77 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import Controller from '@ember/controller';
import { set, action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
export default class ModifierController extends Controller {
differentSizedModels = ['A', 'B'.repeat(100), 'D'.repeat(50), 'C'.repeat(20)];
@tracked records = [
{ fruit: 'avocado', day: 'Monday' },
{ fruit: 'banana', day: 'Tuesday' },
{ fruit: 'cashew', day: 'Wednesday' },
{ fruit: 'watermelon', day: 'Thursday' },
{ fruit: 'durian', day: 'Friday' },
{ fruit: 'apple', day: 'Saturday' },
{ fruit: 'lemon', day: 'Sunday' },
];
@tracked mutableRecords = ['Zero', 'One', 'Two', 'Three', 'Four'];
@action handleDragChange(reordered) {
this.records = reordered;
}
handleVisualClass = {
UP: 'sortable-handle-up',
DOWN: 'sortable-handle-down',
LEFT: 'sortable-handle-left',
RIGHT: 'sortable-handle-right',
};
itemVisualClass = 'sortable-item--active';
a11yAnnouncementConfig = {
ACTIVATE: function ({ a11yItemName, index, maxLength, direction }) {
let message = `${a11yItemName} at position, ${index + 1} of ${maxLength}, is activated to be repositioned.`;
if (direction === 'y') {
message += 'Press up and down keys to change position,';
} else {
message += 'Press left and right keys to change position,';
}
message += ' Space to confirm new position, Escape to cancel.';
return message;
},
MOVE: function ({ a11yItemName, index, maxLength, delta }) {
return `${a11yItemName} is moved to position, ${
index + 1 + delta
} of ${maxLength}. Press Space to confirm new position, Escape to cancel.`;
},
CONFIRM: function ({ a11yItemName }) {
return `${a11yItemName} is successfully repositioned.`;
},
CANCEL: function ({ a11yItemName }) {
return `Cancelling ${a11yItemName} repositioning`;
},
};
@action
updateDifferentSizedModels(newOrder) {
set(this, 'differentSizedModels', newOrder);
}
@action
update(newOrder, draggedModel) {
set(this, 'model.items', newOrder);
set(this, 'model.dragged', draggedModel);
}
@action
updateGrid(newOrder, draggedModel) {
set(this, 'model.itemsGrid', newOrder);
set(this, 'model.dragged', draggedModel);
}
@action
updateGrid2(newOrder, draggedModel) {
set(this, 'model.itemsGrid2', newOrder);
set(this, 'model.dragged', draggedModel);
}
@action
updateMutable(newOrder, draggedMode) {
this.mutableRecords = newOrder;
}
@action
removeItemHorizontal(item) {
this.mutableRecords = this.mutableRecords.filter(
(record) => record !== item,
);
}
@action
addItemToHorizontal() {
this.mutableRecords = [
...this.mutableRecords,
`Item ${this.mutableRecords.length + 1}`,
];
}
}