Skip to content

Commit 9360e78

Browse files
committed
Some more 5.2 examples
1 parent da7b4d9 commit 9360e78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+18045
-48
lines changed

ui-playground/plugin/manifest.json

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,39 @@
33
"name": "HTML Playground",
44
"version": "1.0.0",
55
"main": "index.html",
6-
"manifestVersion": 4,
7-
"host": {
8-
"app": "PS",
9-
"minVersion": "22.0.0"
6+
"manifestVersion": 5,
7+
"requiredPermissions": {
8+
"allowCodeGenerationFromStrings": true,
9+
"webivew": {
10+
"allow": "yes"
11+
},
12+
"launchProcess": "request"
13+
},
14+
"featureFlags": {
15+
"experimentalTableV1Support": true
16+
},
17+
"host": [
18+
{
19+
"app": "UXPS",
20+
"minVersion": "1.0.0"
1021
},
22+
{
23+
"app": "UXPT",
24+
"minVersion": "0.1.0"
25+
},
26+
{
27+
"app": "PS",
28+
"minVersion": "22.0.0",
29+
"data": {
30+
"apiVersion": 1
31+
}
32+
}, {
33+
"app": "XD",
34+
"minVersion": "36.0.0"
35+
}, {
36+
"app": "exotest",
37+
"minVersion": "1.0.0"
38+
}],
1139
"strings": {
1240
"plugin-title": { "default": "HTML Playground" },
1341
"about-command": { "default": "About" },

ui-playground/src/App.css

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
.tabbar {
22
display: flex;
33
flex: 0 0 auto;
4-
padding: 12px;
4+
padding: 4px 0;
55
background-color: rgba(0,0,0,.25);
6-
border-bottom-left-radius: 4px;
7-
border-bottom-right-radius: 4px;
86
flex-wrap: wrap;
97
}
108
.tabsection {
@@ -13,11 +11,15 @@
1311
flex-direction: row;
1412
flex-wrap: wrap;
1513
}
16-
.tabsection:nth-of-type(2) {
14+
.tabsection:nth-of-type(3) {
1715
justify-content: flex-end;
1816
}
1917

20-
.tabsection * {
18+
.tabsection > * {
19+
margin: 0 4px;
20+
}
21+
22+
.tabsection sp-checkbox {
2123
margin: 0 4px;
2224
}
2325

@@ -32,18 +34,21 @@
3234
flex: 1 1 auto;
3335
display: flex;
3436
flex-direction: column;
35-
padding: 16px;
3637
}
3738

3839
.editor * {
3940
flex: 1 1 auto;
4041
}
4142

42-
textarea {
43-
appearance: none;
44-
position: relative;
45-
border-radius: 4px;
46-
padding: 16px;
43+
.preview {
44+
overflow: auto;
45+
height: 200px;
46+
}
47+
48+
.editor textarea, .editor sp-textarea {
49+
width: 100%;
50+
margin: 0;
51+
margin-bottom: 1px;
4752
}
4853

4954
.err {
@@ -55,9 +60,7 @@ textarea {
5560
color: white;
5661
fill: currentColor;
5762
padding: 16px;
58-
margin: 24px;
5963
margin-top: 0;
60-
border-radius: 4px;
6164
}
6265
.err svg {
6366
flex: 0 0 auto;
@@ -72,4 +75,30 @@ textarea {
7275
color: white;
7376
}
7477

78+
.sideLabel {
79+
position: relative;
80+
margin-left: 50px;
81+
width: 150px;
82+
}
83+
84+
.sideLabel sp-label {
85+
position: absolute;
86+
left: -50px;
87+
line-height: 24px;
88+
}
7589

90+
.info {
91+
display: flex;
92+
align-items: baseline;
93+
justify-content: center;
94+
padding: 0 16px;
95+
}
96+
.info > * {
97+
margin: 0 8px;
98+
}
99+
i {
100+
font-style: italic;
101+
}
102+
sp-overlay {
103+
display: inline-block;
104+
}

ui-playground/src/App.jsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from "react";
22
import Sval from "sval";
3+
const Babel = require ("@babel/standalone");
34

45
import "./App.css";
56

@@ -30,17 +31,25 @@ export class App extends AutoUpdatingPanel {
3031
}
3132

3233
executeCode() {
34+
const store = this.props.store;
3335
try {
34-
const code = `"use strict";${this.props.store.js}`;
36+
store.error = "";
37+
const strictCode =`"use strict";${this.props.store.js}`;
38+
const code = store.jsx ? Babel.transform(strictCode, {presets: ["env", "react"]}).code : strictCode;
3539
const interpreter = new Sval(options);
40+
interpreter.import("React", require("react"));
41+
interpreter.import("ReactDOM", require("react-dom"));
3642
interpreter.import("uxp", require("uxp"));
3743
interpreter.import("os", require("os"));
38-
interpreter.import("rootNode", this.root.current)
44+
interpreter.import("rootNode", document.querySelector("#__preview__") || this.root.current);
45+
interpreter.import("console", Object.assign({}, console, {
46+
log (...msg) {store.error = msg.join(""); },
47+
error (...msg) {store.error = "ERROR: " + msg.join(""); }
48+
}));
3949
interpreter.run(code);
40-
this.props.store.error = "";
4150
}
4251
catch(err) {
43-
this.props.store.error = err.message;
52+
store.error = err.message;
4453
}
4554
}
4655

ui-playground/src/components/About.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class About extends React.Component {
1818
</sp-body>
1919
<sp-body class="well">
2020
<sp-icon name="ui:InfoSmall" size="s"></sp-icon>
21-
This plugin does _not_ support running React code. You may need to make some adjustments before
21+
This plugin does <i>not</i> support running React code. You may need to make some adjustments before
2222
writing your plugin using React based on any findings here.
2323
</sp-body>
2424
<sp-detail>VERSIONS</sp-detail>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from "react";
2+
import { WC } from "../components/WC.jsx";
3+
4+
export function DropdownMenu({label, items, onClick} = {}) {
5+
6+
function menuItemClicked(e) {
7+
const target = e.target;
8+
const whichMenu = target.id;
9+
10+
// if no id, then we can't do anything with it -- bail
11+
if (!whichMenu) return;
12+
13+
// basic debouncing
14+
if (target.getAttribute("ignore")) return;
15+
target.setAttribute("ignore", "ignore");
16+
17+
const menuEl = target.parentElement;
18+
const popover = menuEl.parentElement;
19+
20+
// BUG: even though the popover is open, it shows as false. Setting it to false
21+
// won't close the popover because the value hasn't changed. This bit of hacky
22+
// code corrects this by forcing the popover open (does nothing really, since it
23+
// already is), and then we can safely hide it.
24+
popover.open = true;
25+
setTimeout(() => {
26+
// close the popover
27+
popover.open = false;
28+
29+
// clear the selected item
30+
menuEl.selectedIndex = -1;
31+
32+
const item = items.find(({id: candidateId, handler}={}) => candidateId === whichMenu);
33+
if (item && item.handler) {
34+
// add a timeout in case we have a dialog -- show it too fast and it and the popover
35+
// start having issues
36+
setTimeout(() => item.handler(), 100);
37+
}
38+
}, 16);
39+
40+
// clear the flag for debounce
41+
setTimeout(() => {
42+
target.removeAttribute("ignore");
43+
}, 100);
44+
}
45+
46+
function transformItems(items) {
47+
return items.map(({id, label}={}) => label !== "-" ? <sp-menu-item id={id} key={id}>{label}</sp-menu-item>
48+
: <sp-divider></sp-divider>);
49+
}
50+
51+
return (<WC onClick={menuItemClicked}>
52+
<sp-overlay style={{display: "inline-block"}}>
53+
<sp-action-button size="s" slot="trigger" quiet>{label}</sp-action-button>
54+
<sp-popover size="s" offset="0" placement="bottom" alignment="bottom" appearance="none" slot="click">
55+
<sp-menu size="s" style={{width: "200px"}}>
56+
{transformItems(items)}
57+
</sp-menu>
58+
</sp-popover>
59+
</sp-overlay>
60+
</WC>);
61+
}

ui-playground/src/components/Icons.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import React from "react";
22

3+
export const SmallPlayIcon = () => (
4+
<svg xmlns="http://www.w3.org/2000/svg" height="14" viewBox="0 0 18 18" width="14">
5+
<path d="M4.73,2H3.5a.5.5,0,0,0-.5.5v13a.5.5,0,0,0,.5.5H4.73a1,1,0,0,0,.5035-.136l11.032-6.433a.5.5,0,0,0,0-.862L5.2335,2.136A1,1,0,0,0,4.73,2Z" />
6+
</svg>
7+
);
38
export const PlayIcon = () => (
49
<svg xmlns="http://www.w3.org/2000/svg" height="18" viewBox="0 0 18 18" width="18">
510
<path d="M4.73,2H3.5a.5.5,0,0,0-.5.5v13a.5.5,0,0,0,.5.5H4.73a1,1,0,0,0,.5035-.136l11.032-6.433a.5.5,0,0,0,0-.862L5.2335,2.136A1,1,0,0,0,4.73,2Z" />

ui-playground/src/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ export const VIEWS = {
22
HTML: "html",
33
STYLES: "styles",
44
JS: "js",
5+
PREVIEW: "preview",
56
0: "html",
67
1: "styles",
7-
2: "js"
8+
2: "js",
9+
3: "preview"
810
};

ui-playground/src/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ entrypoints.setup({
2727
commands: {
2828
showAbout: aboutController
2929
},
30-
});
30+
});

0 commit comments

Comments
 (0)