Skip to content

Commit e9b0952

Browse files
authored
Minor cleanup (#67)
* Update package.json name for examples * Delete package-lock.json * Fix lockfile * Fix linter errors * Format examples folder * Lowercase REST/ folder
1 parent 617c8f8 commit e9b0952

File tree

16 files changed

+102
-4018
lines changed

16 files changed

+102
-4018
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist
22
package.json
33
package-lock.json
4+
examples/rest/python-flask-starter/templates/

examples/connect-firebase/app.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@
77
<script src="https://miro.com/app/static/sdk/v2/miro.js"></script>
88
</head>
99
<body>
10-
1110
<div class="grid wrapper">
1211
<div class="cs1 ce12">
1312
<button id="save-btn" class="button button-primary">
1413
Save Selection as Template
1514
</button>
1615
<div class="form-group">
17-
<input id="search-bar" class="input" type="text" placeholder="Search templates"/>
16+
<input
17+
id="search-bar"
18+
class="input"
19+
type="text"
20+
placeholder="Search templates"
21+
/>
1822
</div>
1923
<p>Drag templates into your board</p>
2024
<div id="templates"></div>

examples/connect-firebase/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "miro-templates-app",
2+
"name": "connect-firebase",
33
"version": "0.1.0",
44
"licence": "MIT",
55
"scripts": {
@@ -14,4 +14,4 @@
1414
"@mirohq/websdk-types": "latest",
1515
"vite": "2.7.13"
1616
}
17-
}
17+
}

examples/connect-firebase/src/app.js

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
/* global miro */
12
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.10/firebase-app.js";
2-
import { getDatabase, ref, set, get } from "https://www.gstatic.com/firebasejs/9.6.10/firebase-database.js";
3+
import {
4+
getDatabase,
5+
ref,
6+
set,
7+
get,
8+
} from "https://www.gstatic.com/firebasejs/9.6.10/firebase-database.js";
39

410
const firebaseConfig = {
511
apiKey: "YOUR-API-KEY",
@@ -8,78 +14,80 @@ const firebaseConfig = {
814
projectId: "YOUR-PROJECT-ID",
915
storageBucket: "YOUR-BUCKET.appspot.com",
1016
messagingSenderId: "YOUR-SENDER-ID",
11-
appId: "YOUR-APP-ID"
17+
appId: "YOUR-APP-ID",
1218
};
1319

1420
// Initialize Firebase
1521
const app = initializeApp(firebaseConfig);
16-
const db = getDatabase( app );
22+
const db = getDatabase(app);
1723

18-
async function getTemplatesFromDB( userId ) {
19-
const data = await get( ref( db, "templates/" + userId ) );
20-
if( data.exists() ) {
24+
async function getTemplatesFromDB(userId) {
25+
const data = await get(ref(db, "templates/" + userId));
26+
if (data.exists()) {
2127
return data.val();
2228
}
2329
return [];
2430
}
2531

26-
function saveTemplatesToDB( userId, templates ) {
27-
set( ref( db, "templates/" + userId ), templates );
32+
function saveTemplatesToDB(userId, templates) {
33+
set(ref(db, "templates/" + userId), templates);
2834
}
2935

3036
let templates = [];
3137
let filter = "";
3238

33-
window.saveTemplate = ( userId, name, items ) => {
39+
window.saveTemplate = (userId, name, items) => {
3440
// Calculate center
35-
let totalX = 0, totalY = 0;
36-
items.forEach( item => {
41+
let totalX = 0,
42+
totalY = 0;
43+
items.forEach((item) => {
3744
totalX += item.x;
3845
totalY += item.y;
3946
});
4047
const center = { x: totalX / items.length, y: totalY / items.length };
4148

4249
// Save to the cloud
43-
templates.push( { name, items, center });
44-
saveTemplatesToDB( userId, templates );
45-
displayTemplates( userId, templates );
46-
}
50+
templates.push({ name, items, center });
51+
saveTemplatesToDB(userId, templates);
52+
displayTemplates(userId, templates);
53+
};
4754

48-
window.deleteTemplate = ( userId, index ) => {
49-
templates.splice( index, 1 );
50-
saveTemplatesToDB( userId, templates );
51-
displayTemplates( userId, templates );
52-
}
55+
window.deleteTemplate = (userId, index) => {
56+
templates.splice(index, 1);
57+
saveTemplatesToDB(userId, templates);
58+
displayTemplates(userId, templates);
59+
};
5360

54-
function displayTemplates( userId, templates ) {
55-
const templateList = document.getElementById( "templates" );
61+
function displayTemplates(userId, templates) {
62+
const templateList = document.getElementById("templates");
5663
templateList.innerHTML = "";
57-
templates.forEach( ( t, i ) => {
58-
if( !t.name.toLowerCase().includes( filter.toLowerCase() ) ) { return; }
59-
templateList.innerHTML +=
60-
`<div class="cs1 ce12 miro-draggable" data-index="${i}" style="padding: 5px; margin: 5px; border: 5px solid black;">
64+
templates.forEach((t, i) => {
65+
if (!t.name.toLowerCase().includes(filter.toLowerCase())) {
66+
return;
67+
}
68+
templateList.innerHTML += `<div class="cs1 ce12 miro-draggable" data-index="${i}" style="padding: 5px; margin: 5px; border: 5px solid black;">
6169
<h2>${t.name} - <span onclick="deleteTemplate('${userId}', ${i})">x</span></h2>
6270
</div>`;
6371
});
6472
}
6573

66-
async function createWidgetFromJson( item, x, y ) {
67-
const clone = Object.assign( {}, item, { x: item.x + x, y: item.y + y } );
68-
switch( clone.type ) {
74+
async function createWidgetFromJson(item, x, y) {
75+
const clone = Object.assign({}, item, { x: item.x + x, y: item.y + y });
76+
switch (clone.type) {
6977
case "card":
70-
await miro.board.createCard( clone );
78+
await miro.board.createCard(clone);
7179
break;
7280
case "frame":
73-
await miro.board.createFrame( clone );
81+
await miro.board.createFrame(clone);
7482
break;
7583
case "shape":
76-
await miro.board.createShape( clone );
84+
await miro.board.createShape(clone);
7785
break;
7886
case "sticky_note":
79-
await miro.board.createStickyNote( clone );
87+
await miro.board.createStickyNote(clone);
8088
break;
8189
case "text":
82-
await miro.board.createText( clone );
90+
await miro.board.createText(clone);
8391
break;
8492
}
8593
}
@@ -89,16 +97,16 @@ async function init() {
8997
const user = await miro.board.getUserInfo();
9098

9199
// Load templates from the cloud
92-
templates = await getTemplatesFromDB( user.id );
93-
displayTemplates( user.id, templates );
100+
templates = await getTemplatesFromDB(user.id);
101+
displayTemplates(user.id, templates);
94102

95103
// Save button handler
96-
document.getElementById( "save-btn" ).onclick = async () => {
97-
const name = prompt( "Please enter a name for the template" );
104+
document.getElementById("save-btn").onclick = async () => {
105+
const name = prompt("Please enter a name for the template");
98106
// Save items
99107
const items = await miro.board.getSelection();
100108
// Remove unnecessary properties
101-
items.forEach( item => {
109+
items.forEach((item) => {
102110
delete item.id;
103111
delete item.parentId;
104112
delete item.height; // Note: only save the width and not the height
@@ -107,21 +115,21 @@ async function init() {
107115
delete item.modifiedAt;
108116
delete item.modifiedBy;
109117
});
110-
saveTemplate( user.id, name, items );
118+
window.saveTemplate(user.id, name, items);
111119
};
112120

113121
// Search handler
114-
document.getElementById( "search-bar" ).addEventListener( "input", (e) => {
122+
document.getElementById("search-bar").addEventListener("input", (e) => {
115123
filter = e.target.value;
116-
displayTemplates( user.id, templates );
124+
displayTemplates(user.id, templates);
117125
});
118126

119127
// Drag-n-drop handler
120-
miro.board.ui.on( "drop", async ({ x, y, target }) => {
121-
const index = target.getAttribute( "data-index" );
122-
const template = templates[ index ];
123-
template.items.forEach( item => {
124-
createWidgetFromJson( item, x - template.center.x, y - template.center.y );
128+
miro.board.ui.on("drop", async ({ x, y, target }) => {
129+
const index = target.getAttribute("data-index");
130+
const template = templates[index];
131+
template.items.forEach((item) => {
132+
createWidgetFromJson(item, x - template.center.x, y - template.center.y);
125133
});
126134
});
127135
}

examples/connect-firebase/src/assets/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import 'mirotone/dist/styles.css';
1+
@import "mirotone/dist/styles.css";
22

33
*,
44
*:before,

examples/connect-firebase/src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
/* global miro */
2+
13
async function init() {
2-
miro.board.ui.on('icon:click', async () => {
3-
await miro.board.ui.openPanel({url: 'app.html'});
4+
miro.board.ui.on("icon:click", async () => {
5+
await miro.board.ui.openPanel({ url: "app.html" });
46
});
57
}
68

examples/connect-firebase/vite.config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const path = require('path');
2-
const fs = require('fs');
3-
const {defineConfig} = require('vite');
1+
const path = require("path");
2+
const fs = require("fs");
3+
const { defineConfig } = require("vite");
44

55
// make sure vite picks up all html files in root, needed for vite build
66
const allHtmlEntries = fs
7-
.readdirSync('.')
8-
.filter((file) => path.extname(file) === '.html')
7+
.readdirSync(".")
8+
.filter((file) => path.extname(file) === ".html")
99
.reduce((acc, file) => {
10-
acc[path.basename(file, '.html')] = path.resolve(__dirname, file);
10+
acc[path.basename(file, ".html")] = path.resolve(__dirname, file);
1111

1212
return acc;
1313
}, {});

0 commit comments

Comments
 (0)