-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathmain.js
114 lines (102 loc) · 3.46 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
103
104
105
106
107
108
109
110
111
112
113
114
const Storage = require('./Storage.js')
const insertImage = require('./insertImage.js')
const replaceSelectionsWithImages = require('./replaceSelectionsWithImages.js')
const copySvgToClipboard = require('./copySvgToClipboard.js')
const canInsertInSelection = require('./canInsertInSelection.js')
global.settings = null
global.insertSVG = async (selection, file) => {
await copySvgToClipboard(file)
}
global.insertRaster = async (selection, file) => {
console.log('xd insertRaster', selection.items.length, file)
if (canInsertInSelection(selection)) {
await replaceSelectionsWithImages(selection, [file])
} else {
await insertImage(selection, file)
}
}
global.insertSVGs = async (selection, files) => {
await copySvgToClipboard(files[0])
}
global.insertRasters = async (selection, files) => {
console.log('xd insertRasters', selection.items.length, files)
// We can't fill if the Artboard is selected
// Thus insertImage in case of Artboard is selected
if (canInsertInSelection(selection)) {
await replaceSelectionsWithImages(selection, files)
} else {
await insertImage(selection, files[0])
}
}
global.log = (args) => {
// const { method, data } = args
console.log('log from xd web', args)
// if (method === 'insertRaster') {
// console.log(data.url)
// const { editDocument } = require('application')
// editDocument({ editLabel: 'Increase rectangle size' }, function (selection) {
// global[method](selection, data)
// })
// }
}
module.exports = {
panels: {
panelCommand: {
async show (event) {
// Load All Settings
global.settings = await Storage.all()
console.log('xd: settings loaded', global.settings)
// Show Panel
const getPanel = require('./main.common.js').getPanel
event.node.appendChild(getPanel())
},
hide (event) {
Storage.saveAll(global.settings).then(() => console.log('xd: storage saved.'))
event.node.firstChild.remove()
},
update () {
// console.log('update')
}
}
},
commands: {
// menuCommand: async function (selection) {
// try {
// // Load All Settings
// global.settings = await Storage.all()
// console.log('xd: storage', global.settings)
// const getDialog = require('./main.common.js').getDialog
// const dialog = getDialog()
// dialog.addEventListener('close', () => {
// // dialog is closed at this point
// // Save Settings
// Storage.saveAll(global.settings).then(() => console.log('xd: storage saved.'))
// })
// const { method, data } = await dialog.showModal()
// // Do the activity in Artboard
// console.log('method', method)
// if (global[method]) {
// await global[method](selection, data)
// }
// // Else it'll just close the box
// } catch (error) {
// console.log(error)
// }
// },
insertImage: async function (selection) {
// Insert Image in the artboard
// await insertImage(selection)
// Fill Image to the Shape
// await replaceSelectionsWithImages(selection)
// Insert SVG
console.log('selection is', selection.insertionParent, selection.items[0])
await global.insertRasters(selection, [
{
format: 'png',
url: 'https://cdn.iconscout.com/icon/premium/png-128-thumb/alert-20-106197.png',
name: 'Tarun'
}
])
}
}
}