forked from miroapp/app-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sidebar.html
80 lines (73 loc) · 2.37 KB
/
sidebar.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" href="https://miro.com/app/static/styles.1.0.css" />
<style>
.rtb-sidebar-caption {
font-size: 14px;
font-weight: bold;
color: rgba(0, 0, 0, 0.8);
padding: 24px 0 0 24px;
}
.no-selected-widget {
font-size: 18px;
text-align: center;
margin-top: 60px;
color: #999;
}
.widget-info {
padding: 20px 24px 0 24px;
height: 100%;
}
.editor {
width: 310px;
height: calc(100% - 240px);
border: 1px solid #ccc;
padding: 10px;
box-sizing: border-box;
font-family: Arial;
font-size: 14px;
margin: 0 -10px;
resize: none;
}
</style>
</head>
<body>
<div class="rtb-sidebar-caption">Import widgets</div>
<div class="widget-info">
<textarea placeholder="Paste text here" id="editor" class="editor"></textarea><br /><br />
<label> Use RegExp <input type="checkbox" id="use-regexp" checked="checked" /> </label><br /><br />
<label> Split string <input type="text" id="split-string" value="\n" /> </label><br /><br />
<label>
Create widget type
<select>
<option value="sticker" selected>Sticker</option>
<option value="text">Text</option>
</select> </label
><br /><br />
<button onclick="onCreateClick()">Create widgets from text</button>
</div>
<script src="https://miro.com/app/static/sdk.1.1.js"></script>
<script>
const editorTextarea = document.querySelector('#editor')
const useRegexpCheckbox = document.querySelector('#use-regexp')
const splitStringInput = document.querySelector('#split-string')
async function onCreateClick() {
const text = editorTextarea.value
const useRegexp = useRegexpCheckbox.checked
const splitValue = splitStringInput.value
const splitter = useRegexp ? new RegExp(splitValue) : splitValue
const chunks = text.split(splitter)
let i = 0
for (let index = 0; index < chunks.length; index++) {
const chunk = chunks[index]
if (chunk.trim()) {
i++
miro.board.widgets.create({type: 'sticker', text: chunk, x: i * 280})
}
}
}
</script>
</body>
</html>