Skip to content

Commit e679442

Browse files
committed
add panel sample
1 parent 16368db commit e679442

16 files changed

+10177
-0
lines changed
357 Bytes
Loading
607 Bytes
Loading

03-01-panel-sample/main.js

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const { selection, Text } = require('scenegraph');
2+
const clipboard = require('clipboard');
3+
4+
let panel;
5+
6+
function create() {
7+
panel = document.createElement('div');
8+
panel.setAttribute('id', 'textContainers');
9+
10+
return panel;
11+
}
12+
13+
function show(event) {
14+
if (!panel) event.node.appendChild(create());
15+
}
16+
17+
function hide(event) {}
18+
19+
function extractAndAddText(sceneNode) {
20+
const textContainers = document.querySelector('#textContainers');
21+
sceneNode.forEach(item => {
22+
if (item instanceof Text) {
23+
const textBoxContainer = document.createElement('div');
24+
const textLabel = document.createElement('div');
25+
textLabel.innerHTML = `${item.name}`;
26+
const textForm = document.createElement('form');
27+
const textInput = document.createElement('textarea');
28+
const copyButton = document.createElement('button');
29+
textInput.setAttribute('readonly', 'true');
30+
textInput.textContent = `${item.text}`;
31+
copyButton.innerHTML = 'copy';
32+
textBoxContainer.appendChild(textLabel);
33+
textForm.appendChild(textInput);
34+
textForm.appendChild(copyButton);
35+
textBoxContainer.appendChild(textLabel);
36+
textBoxContainer.appendChild(textForm);
37+
38+
copyButton.addEventListener('click', function(e) {
39+
(function(ev, ti) {
40+
clipboard.copyText(ti.textContent);
41+
})(e, textInput);
42+
});
43+
44+
textContainers.appendChild(textBoxContainer);
45+
} else if (item.children) {
46+
extractAndAddText(item.children);
47+
}
48+
});
49+
}
50+
51+
async function update() {
52+
const textContainers = document.querySelector('#textContainers');
53+
54+
while (textContainers.firstChild) {
55+
textContainers.removeChild(textContainers.firstChild);
56+
}
57+
58+
if (selection.items.length) {
59+
extractAndAddText(selection.items);
60+
}else{
61+
console.log('no item');
62+
const message = document.createElement('div');
63+
message.innerHTML = `Select Objects with text`;
64+
textContainers.appendChild(message);
65+
}
66+
}
67+
68+
module.exports = {
69+
panels: {
70+
example: {
71+
show,
72+
hide,
73+
update,
74+
},
75+
},
76+
};

03-01-panel-sample/manifest.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"id": "xdjp0301",
3+
"version": "0.0.1",
4+
"name": "Copy text to Clipboard",
5+
"icons": [
6+
{
7+
"width": 24,
8+
"height": 24,
9+
"path": "images/icon-24px.png"
10+
},
11+
{
12+
"width": 48,
13+
"height": 48,
14+
"path": "images/icon-48px.png"
15+
}
16+
],
17+
"host": {
18+
"app": "XD",
19+
"minVersion": "21.0"
20+
},
21+
"uiEntryPoints": [
22+
{
23+
"type": "panel",
24+
"label": "Copy text to Clipboard",
25+
"panelId": "example"
26+
}
27+
]
28+
}
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
end_of_line = lf
10+
# editorconfig-tools is unable to ignore longs strings or urls
11+
max_line_length = null
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.git/
2+
node_modules/
3+
docs/
4+
build/
5+
package-lock.json

03-02-panel-sample-webpack/.eslintrc

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"extends": ["airbnb", "plugin:prettier/recommended"],
3+
"plugins": [],
4+
"parserOptions": {},
5+
"env": {
6+
"browser": true
7+
},
8+
"globals": {},
9+
"rules": {
10+
"no-unused-vars": "warn",
11+
"no-console": "warn",
12+
"import/no-unresolved": [
13+
"warn",
14+
{
15+
"ignore": ["application", "clipboard", "commands", "secenegraph", "uxp"]
16+
}
17+
],
18+
"no-param-reassign": [
19+
"error",
20+
{
21+
"props": true,
22+
"ignorePropertyModificationsFor": ["selection"]
23+
}
24+
],
25+
"prettier/prettier": [
26+
"error",
27+
{
28+
"singleQuote": true,
29+
"trailingComma": "es5"
30+
}
31+
]
32+
}
33+
}

03-02-panel-sample-webpack/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
build
3+
build.xdx

03-02-panel-sample-webpack/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Red square of arbitrary size
2+
3+
## Setup
4+
5+
```bash
6+
npm install
7+
```
8+
9+
## Live-loading plugin for `Develop` folder
10+
11+
Deploy the plugin and monitor updates of files.
12+
13+
```bash
14+
npm start
15+
```
16+
17+
## Deploy plugin to the `Develop` Folder
18+
19+
```bash
20+
npm deploy
21+
```
22+
23+
## Usage
24+
25+
#### 1. Reload plugins:
26+
`Plugins` > `Development` > `Reload Plugins` or press `shift + command(ctrl) + R` keys.
27+
#### 2. Run the plugin:
28+
`Plugins` > `Insert a red square of arbitrary size`
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"id": "XDJP0302",
3+
"version": "0.0.1",
4+
"name": "Copy text to Clipboard",
5+
"icons": [
6+
{
7+
"width": 24,
8+
"height": 24,
9+
"path": "images/icon-24px.png"
10+
},
11+
{
12+
"width": 48,
13+
"height": 48,
14+
"path": "images/icon-48px.png"
15+
}
16+
],
17+
"host": {
18+
"app": "XD",
19+
"minVersion": "21.0"
20+
},
21+
"uiEntryPoints": [
22+
{
23+
"type": "panel",
24+
"label": "Copy text to Clipboard",
25+
"panelId": "example"
26+
}
27+
]
28+
}

0 commit comments

Comments
 (0)