Skip to content

Commit 27b3292

Browse files
author
Nitin Khanna
committed
first push of code
1 parent 73f1e83 commit 27b3292

File tree

6 files changed

+779
-0
lines changed

6 files changed

+779
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

Contents/Executables/Main.js

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/*
2+
React Studio wrapper for the 'react-tsparticles' npm package.
3+
4+
- 2020 / Nitin Khanna / @nitinthewiz / automedia.ai
5+
*/
6+
7+
8+
// -- plugin info requested by host app --
9+
10+
this.describePlugin = function(id, lang) {
11+
switch (id) {
12+
case 'displayName':
13+
return "tsparticles";
14+
15+
case 'shortDisplayText':
16+
return "tsparticles!";
17+
18+
case 'defaultNameForNewInstance':
19+
return "tsparticles";
20+
}
21+
}
22+
23+
24+
// -- private variables --
25+
26+
this._data = {
27+
declarative: ""
28+
};
29+
30+
31+
// -- persistence, i.e. saving and loading --
32+
33+
this.persist = function() {
34+
return this._data;
35+
}
36+
37+
this.unpersist = function(data) {
38+
this._data = data;
39+
}
40+
41+
42+
// -- inspector UI --
43+
44+
this.inspectorUIDefinition = [
45+
{
46+
"type": "label",
47+
"text": "Paste the tsParticles config JSON below.\nDimensions come from React Studio canvas",
48+
"height": 40,
49+
},
50+
{
51+
"type": "textinput",
52+
"id": "declarative",
53+
"label": "JSON Declaration",
54+
"actionBinding": "this.onUIChange",
55+
"multiline": true,
56+
"height": 600
57+
}
58+
];
59+
60+
this._uiTextFields = [ 'declarative' ];
61+
this._uiCheckboxes = [];
62+
this._uiNumberFields = [];
63+
this._uiColorPickers = [];
64+
this._uiComponentPickers = [];
65+
66+
this._accessorForDataKey = function(key) {
67+
if (this._uiTextFields.includes(key)) return 'text';
68+
else if (this._uiCheckboxes.includes(key)) return 'checked';
69+
else if (this._uiNumberFields.includes(key)) return 'numberValue';
70+
else if (this._uiColorPickers.includes(key)) return 'rgbaArrayValue';
71+
else if (this._uiComponentPickers.includes(key)) return 'componentName';
72+
return null;
73+
}
74+
75+
this.onCreateUI = function() {
76+
var ui = this.getUI();
77+
for (var controlId in this._data) {
78+
var prop = this._accessorForDataKey(controlId);
79+
if (prop) {
80+
try {
81+
ui.getChildById(controlId)[prop] = this._data[controlId];
82+
} catch (e) {
83+
console.log("** can't set ui value for key "+controlId+", prop "+prop);
84+
}
85+
}
86+
}
87+
}
88+
89+
this.onUIChange = function(controlId) {
90+
var ui = this.getUI();
91+
var prop = this._accessorForDataKey(controlId);
92+
if (prop) {
93+
this._data[controlId] = ui.getChildById(controlId)[prop];
94+
} else {
95+
console.log("** no data property found for controlId "+controlId);
96+
}
97+
}
98+
99+
100+
// -- plugin preview --
101+
102+
this.renderIcon = function(canvas) {
103+
var ctx = canvas.getContext('2d');
104+
var w = canvas.width;
105+
var h = canvas.height;
106+
ctx.save();
107+
if (this.icon == null) {
108+
// got the Particles logo online
109+
var path = Plugin.getPathForResource("particles_logo.png");
110+
this.icon = Plugin.loadImage(path);
111+
}
112+
var iconW = this.icon.width;
113+
var iconH = this.icon.height;
114+
var aspectScale = Math.min(w/iconW, h/iconH);
115+
var scale = 0.9 * aspectScale; // add some margin around icon
116+
iconW *= scale;
117+
iconH *= scale;
118+
ctx.drawImage(this.icon, (w-iconW)*0.5, (h-iconH)*0.5, iconW, iconH);
119+
ctx.restore();
120+
};
121+
122+
this.renderEditingCanvasPreview = function(canvas, controller) {
123+
this._renderPreview(canvas, controller);
124+
}
125+
126+
this._renderPreview = function(canvas, controller) {
127+
var ctx = canvas.getContext('2d');
128+
var w = canvas.width;
129+
var h = canvas.height;
130+
ctx.save();
131+
132+
if (this.icon == null) {
133+
var path = Plugin.getPathForResource("particles_logo.png");
134+
this.icon = Plugin.loadImage(path);
135+
}
136+
var iconW = this.icon.width;
137+
var iconH = this.icon.height;
138+
var aspectScale = Math.min(w/iconW, h/iconH);
139+
var scale = 0.9 * aspectScale; // add some margin around icon
140+
iconW *= scale;
141+
iconH *= scale;
142+
ctx.drawImage(this.icon, (w-iconW)*0.5, (h-iconH)*0.5, iconW, iconH);
143+
ctx.restore();
144+
145+
}
146+
147+
148+
// -- code generation, React web --
149+
150+
this.getReactWebPackages = function() {
151+
// Return dependencies that need to be included in the exported project's package.json file.
152+
// Each key is an npm package name that must be imported, and the value is the package version.
153+
//
154+
// Example:
155+
// return { "somepackage": "^1.2.3" }
156+
157+
return {
158+
"react-tsparticles": "^1.17.10"
159+
};
160+
}
161+
162+
this.getReactWebImports = function(exporter) {
163+
var arr = [
164+
{ varName: "Particles", path: "react-tsparticles" }
165+
];
166+
167+
return arr;
168+
}
169+
170+
this.writesCustomReactWebComponent = false;
171+
172+
this.getReactWebJSXCode = function(exporter) {
173+
var json_declaration = this._data.declarative;
174+
175+
var jsx = `<Particles id="tsparticles" options={${JSON.parse(json_declaration)}} />`;
176+
177+
return jsx;
178+
}
179+

Contents/Info.plist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleName</key>
6+
<string>tsparticles</string>
7+
<key>CFBundleIdentifier</key>
8+
<string>com.neonto.plugin.reactstudio.tsparticles</string>
9+
<key>CFBundleVersion</key>
10+
<string>1</string>
11+
<key>CFBundlePackageType</key>
12+
<string>BNDL</string>
13+
<key>CFBundleSignature</key>
14+
<string>????</string>
15+
<key>SPXPluginTypeId</key>
16+
<string>exchange.spx.plugin.element</string>
17+
<key>SPXPluginDependencies</key>
18+
<array>
19+
<string>js/mustache.js</string>
20+
</array>
21+
</dict>
22+
</plist>

0 commit comments

Comments
 (0)