Skip to content

Commit b9737bf

Browse files
committed
apply prettier
1 parent b541574 commit b9737bf

37 files changed

+1070
-1248
lines changed

.babelrc

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
{
2-
"sourceMaps": true,
3-
"presets": [
4-
"@babel/preset-env",
5-
"@babel/preset-typescript"
6-
],
7-
"plugins": [
8-
"@babel/plugin-proposal-class-properties"
9-
]
2+
"sourceMaps": true,
3+
"presets": ["@babel/preset-env", "@babel/preset-typescript"],
4+
"plugins": ["@babel/plugin-proposal-class-properties"]
105
}

.eslintrc.js

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,52 @@
11
module.exports = {
2-
plugins: [
3-
"matrix-org",
2+
plugins: ["matrix-org"],
3+
extends: ["plugin:matrix-org/babel"],
4+
parserOptions: {
5+
project: ["./tsconfig-dev.json"],
6+
},
7+
env: {
8+
browser: true,
9+
},
10+
rules: {
11+
"no-var": ["warn"],
12+
"prefer-rest-params": ["warn"],
13+
"prefer-spread": ["warn"],
14+
"one-var": ["warn"],
15+
"padded-blocks": ["warn"],
16+
"no-extend-native": ["warn"],
17+
"camelcase": ["warn"],
18+
"no-multi-spaces": ["error", { ignoreEOLComments: true }],
19+
"space-before-function-paren": [
20+
"error",
21+
{
22+
anonymous: "never",
23+
named: "never",
24+
asyncArrow: "always",
25+
},
426
],
5-
extends: [
6-
"plugin:matrix-org/babel",
7-
],
8-
parserOptions: {
9-
project: ["./tsconfig-dev.json"],
10-
},
11-
env: {
12-
browser: true,
13-
},
14-
rules: {
15-
"no-var": ["warn"],
16-
"prefer-rest-params": ["warn"],
17-
"prefer-spread": ["warn"],
18-
"one-var": ["warn"],
19-
"padded-blocks": ["warn"],
20-
"no-extend-native": ["warn"],
21-
"camelcase": ["warn"],
22-
"no-multi-spaces": ["error", { "ignoreEOLComments": true }],
23-
"space-before-function-paren": ["error", {
24-
"anonymous": "never",
25-
"named": "never",
26-
"asyncArrow": "always",
27-
}],
28-
"arrow-parens": "off",
29-
"prefer-promise-reject-errors": "off",
27+
"arrow-parens": "off",
28+
"prefer-promise-reject-errors": "off",
29+
"quotes": "off",
30+
"indent": "off",
31+
"no-constant-condition": "off",
32+
"no-async-promise-executor": "off",
33+
},
34+
overrides: [
35+
{
36+
files: ["src/**/*.ts", "test/**/*.ts"],
37+
extends: ["plugin:matrix-org/typescript"],
38+
rules: {
39+
// TypeScript has its own version of this
40+
"babel/no-invalid-this": "off",
41+
3042
"quotes": "off",
31-
"indent": "off",
32-
"no-constant-condition": "off",
33-
"no-async-promise-executor": "off",
43+
},
3444
},
35-
overrides: [{
36-
"files": ["src/**/*.ts", "test/**/*.ts"],
37-
"extends": ["plugin:matrix-org/typescript"],
38-
"rules": {
39-
// TypeScript has its own version of this
40-
"babel/no-invalid-this": "off",
41-
42-
"quotes": "off",
43-
},
44-
}, {
45-
"files": ["src/interfaces/**/*.ts"],
46-
"rules": {
47-
"@typescript-eslint/no-empty-object-type": "off",
48-
},
49-
}],
45+
{
46+
files: ["src/interfaces/**/*.ts"],
47+
rules: {
48+
"@typescript-eslint/no-empty-object-type": "off",
49+
},
50+
},
51+
],
5052
};

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Node.js
1616
uses: actions/setup-node@v4
1717
with:
18-
cache: 'yarn'
18+
cache: "yarn"
1919

2020
- name: Install NPM packages
2121
run: yarn install --frozen-lockfile

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: 🔧 Set up node environment
2828
uses: actions/setup-node@v4
2929
with:
30-
cache: 'yarn'
30+
cache: "yarn"
3131

3232
- name: 🛠️ Setup
3333
run: yarn install --pure-lockfile

.github/workflows/sonarqube.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
name: SonarQube
22
on:
3-
workflow_run:
4-
workflows: ["Build and test"]
5-
types:
6-
- completed
3+
workflow_run:
4+
workflows: ["Build and test"]
5+
types:
6+
- completed
77
concurrency:
8-
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}
9-
cancel-in-progress: true
8+
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch }}
9+
cancel-in-progress: true
1010
jobs:
11-
sonarqube:
12-
name: 🩻 SonarQube
13-
uses: matrix-org/matrix-js-sdk/.github/workflows/sonarcloud.yml@develop
14-
secrets:
15-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
16-
ELEMENT_BOT_TOKEN: ${{ secrets.ELEMENT_BOT_TOKEN }}
11+
sonarqube:
12+
name: 🩻 SonarQube
13+
uses: matrix-org/matrix-js-sdk/.github/workflows/sonarcloud.yml@develop
14+
secrets:
15+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
16+
ELEMENT_BOT_TOKEN: ${{ secrets.ELEMENT_BOT_TOKEN }}

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ JavaScript/TypeScript SDK for widgets & clients to communicate.
66

77
For help and support, visit [#matrix-widgets:matrix.org](https://matrix.to/#/#matrix-widgets:matrix.org) on Matrix.
88

9-
*Disclaimer: Widgets are not yet in the Matrix spec, so this library may not work with other implementations.*
9+
_Disclaimer: Widgets are not yet in the Matrix spec, so this library may not work with other implementations._
1010

1111
## Building
1212

@@ -45,14 +45,14 @@ api.requestCapabilities(StickerpickerCapabilities);
4545

4646
// Add custom action handlers (if needed)
4747
api.on(`action:${WidgetApiToWidgetAction.UpdateVisibility}`, (ev: CustomEvent<IVisibilityActionRequest>) => {
48-
ev.preventDefault(); // we're handling it, so stop the widget API from doing something.
49-
console.log(ev.detail); // custom handling here
50-
api.transport.reply(ev.detail, <IWidgetApiRequestEmptyData>{});
48+
ev.preventDefault(); // we're handling it, so stop the widget API from doing something.
49+
console.log(ev.detail); // custom handling here
50+
api.transport.reply(ev.detail, <IWidgetApiRequestEmptyData>{});
5151
});
5252
api.on("action:com.example.my_action", (ev: CustomEvent<ICustomActionRequest>) => {
53-
ev.preventDefault(); // we're handling it, so stop the widget API from doing something.
54-
console.log(ev.detail); // custom handling here
55-
api.transport.reply(ev.detail, {custom: "reply"});
53+
ev.preventDefault(); // we're handling it, so stop the widget API from doing something.
54+
console.log(ev.detail); // custom handling here
55+
api.transport.reply(ev.detail, { custom: "reply" });
5656
});
5757

5858
// Start the messaging
@@ -63,7 +63,7 @@ api.sendContentLoaded();
6363

6464
// Later, do something else (if needed)
6565
api.setAlwaysOnScreen(true);
66-
api.transport.send("com.example.my_action", {isExample: true});
66+
api.transport.send("com.example.my_action", { isExample: true });
6767
```
6868

6969
For a more complete example, see the `examples` directory of this repo.
@@ -82,8 +82,8 @@ const api = new ClientWidgetApi(widget, iframe, driver);
8282

8383
// The API is automatically started, so we just have to wait for a ready before doing something
8484
api.on("ready", () => {
85-
api.updateVisibility(true).then(() => console.log("Widget knows it is visible now"));
86-
api.transport.send("com.example.my_action", {isExample: true});
85+
api.updateVisibility(true).then(() => console.log("Widget knows it is visible now"));
86+
api.transport.send("com.example.my_action", { isExample: true });
8787
});
8888

8989
// Eventually, stop the API handling

examples/widget/index.css

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@
1414
* limitations under the License.
1515
*/
1616

17-
html, body {
18-
background-color: #ffffff;
19-
color: #000000;
20-
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
17+
html,
18+
body {
19+
background-color: #ffffff;
20+
color: #000000;
21+
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
2122
}
2223

2324
body {
24-
padding: 20px;
25+
padding: 20px;
2526
}
2627

2728
button {
28-
border: none;
29-
color: #ffffff;
30-
background-color: #2a9d8f;
31-
border-radius: 4px;
32-
padding: 6px 12px;
33-
cursor: pointer;
29+
border: none;
30+
color: #ffffff;
31+
background-color: #2a9d8f;
32+
border-radius: 4px;
33+
padding: 6px 12px;
34+
cursor: pointer;
3435
}
3536

3637
#stickyState {
37-
color: #3d5a80;
38+
color: #3d5a80;
3839
}

examples/widget/index.html

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
16-
<!DOCTYPE html>
16+
<!doctype html>
1717
<html lang="en">
18-
<head>
18+
<head>
1919
<title>Example Widget</title>
2020

2121
<!--
@@ -42,8 +42,8 @@
4242

4343
<!-- CSS is just for aesthetics and not important to the example -->
4444
<link href="index.css" rel="stylesheet" />
45-
</head>
46-
<body>
45+
</head>
46+
<body>
4747
<!-- The widget will be loaded into this container -->
4848
<div id="container">Loading...</div>
4949

@@ -55,55 +55,59 @@
5555

5656
<!-- The actual widget functionality -->
5757
<script type="text/javascript">
58-
try {
58+
try {
5959
const qs = parseFragment();
60-
const widgetId = assertParam(qs, 'widgetId');
61-
const userId = assertParam(qs, 'userId');
60+
const widgetId = assertParam(qs, "widgetId");
61+
const userId = assertParam(qs, "userId");
6262
// Allow all origins
63-
const targetOrigin = '*';
63+
const targetOrigin = "*";
6464
let isSticky = false;
6565

6666
// Set up the widget API as soon as possible to avoid problems with the client
6767
const widgetApi = new mxwidgets.WidgetApi(widgetId, targetOrigin);
6868
widgetApi.requestCapability(mxwidgets.MatrixCapabilities.AlwaysOnScreen);
6969

70-
widgetApi.on("ready", function() {
71-
// Fill in the basic widget details now that we're allowed to operate.
72-
document.getElementById("container").innerHTML = "Hello <span id='userId'></span>!<br /><br />"
73-
+ "Currently stuck on screen: <span id='stickyState'></span><br /><br />"
74-
+ "<button onclick='toggleSticky()'>Toggle sticky state</button>";
70+
widgetApi.on("ready", function () {
71+
// Fill in the basic widget details now that we're allowed to operate.
72+
document.getElementById("container").innerHTML =
73+
"Hello <span id='userId'></span>!<br /><br />" +
74+
"Currently stuck on screen: <span id='stickyState'></span><br /><br />" +
75+
"<button onclick='toggleSticky()'>Toggle sticky state</button>";
7576

76-
// Fill in the user ID using innerText to avoid XSS
77-
document.getElementById("userId").innerText = userId;
77+
// Fill in the user ID using innerText to avoid XSS
78+
document.getElementById("userId").innerText = userId;
7879

79-
// Update the UI and ensure that we end up not sticky to start
80-
sendStickyState();
80+
// Update the UI and ensure that we end up not sticky to start
81+
sendStickyState();
8182
});
8283

8384
// Start the widget as soon as possible too, otherwise the client might time us out.
8485
widgetApi.start();
8586

8687
function toggleSticky() {
87-
// called by the button when clicked - toggle the sticky state
88-
isSticky = !isSticky;
89-
sendStickyState();
88+
// called by the button when clicked - toggle the sticky state
89+
isSticky = !isSticky;
90+
sendStickyState();
9091
}
9192

9293
function updateStickyState() {
93-
document.getElementById("stickyState").innerText = isSticky.toString();
94+
document.getElementById("stickyState").innerText = isSticky.toString();
9495
}
9596

9697
function sendStickyState() {
97-
updateStickyState(); // update first to make the UI go faster than the request
98-
widgetApi.setAlwaysOnScreen(isSticky).then(function(r) {
99-
console.log("[Widget] Client responded with: ", r);
100-
}).catch(function(e) {
101-
handleError(e);
98+
updateStickyState(); // update first to make the UI go faster than the request
99+
widgetApi
100+
.setAlwaysOnScreen(isSticky)
101+
.then(function (r) {
102+
console.log("[Widget] Client responded with: ", r);
103+
})
104+
.catch(function (e) {
105+
handleError(e);
102106
});
103107
}
104-
} catch (e) {
108+
} catch (e) {
105109
handleError(e);
106-
}
110+
}
107111
</script>
108-
</body>
112+
</body>
109113
</html>

examples/widget/utils.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
*/
1616

1717
function parseFragment() {
18-
const fragmentString = (window.location.hash || "?");
19-
return new URLSearchParams(fragmentString.substring(Math.max(fragmentString.indexOf('?'), 0)));
18+
const fragmentString = window.location.hash || "?";
19+
return new URLSearchParams(fragmentString.substring(Math.max(fragmentString.indexOf("?"), 0)));
2020
}
2121

2222
function assertParam(fragment, name) {
23-
const val = fragment.get(name);
24-
if (!val) throw new Error(`${name} is not present in URL - cannot load widget`);
25-
return val;
23+
const val = fragment.get(name);
24+
if (!val) throw new Error(`${name} is not present in URL - cannot load widget`);
25+
return val;
2626
}
2727

2828
function handleError(e) {
29-
console.error(e);
30-
document.getElementById("container").innerText = "There was an error with the widget. See JS console for details.";
29+
console.error(e);
30+
document.getElementById("container").innerText = "There was an error with the widget. See JS console for details.";
3131
}

0 commit comments

Comments
 (0)