-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathmain.js
103 lines (95 loc) · 2.03 KB
/
main.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
102
const dom = function(p){
return document.querySelector(p);
}
let commands = require("commands");
function createDialog() {
document.body.innerHTML = layout();
const obj = {};
const dialog = dom("dialog");
const form = dom("form");
const cancel = dom("#cancel");
const copy = dom("#copy");
const ok = dom("#ok");
const posX = dom("#posX");
const posY = dom("#posY");
cancel.onclick = function() {
dialog.close();
};
copy.onclick = form.onsubmit = function(e) {
const obj = {};
obj.x = posX.value;
obj.y = posY.value;
obj.x = posX.value;
obj.copy = true;
dialog.close(obj);
e.preventDefault();
};
ok.onclick = form.onsubmit = function(e) {
const obj = {};
obj.x = posX.value;
obj.y = posY.value;
obj.x = posX.value;
obj.copy = false;
dialog.close(obj);
e.preventDefault();
};
return dialog;
}
function moveItems(arr, x, y){
for (var i = 0; i < arr.length; i++){
arr[i].moveInParentCoordinates(Number(x), Number(y));
}
}
async function menuCommand(selection) {
if (selection.items.length > 0){
const window = createDialog();
const res = await window.showModal();
if (isNaN(res.x) === false && isNaN(res.x) === false){
if (res.copy === true){
commands.duplicate();
}
moveItems(selection.items, res.x, res.y);
}
}
}
function layout(){
const str = `
<style>
form {
width: 280px;
}
.container {
display: flex;
}
input {
width: 140px;
}
footer {
display: table;
}
button {
width: 30%;
}
</style>
<dialog>
<form id="oomoto" method="dialog">
<h1>Move Items Dialog</h1>
<div class="container">
<input id="posX" type="text" placeholder="X" />
<input id="posY" type="text" placeholder="Y" />
</div>
<footer>
<button id="cancel">Cancel</button>
<button id="copy" uxp-variant="primary">Copy</button>
<button id="ok" type="submit" uxp-variant="cta">OK</button>
</footer>
</form>
</dialog>
`;
return str;
}
module.exports = {
commands: {
menuCommand
}
};