-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
215 lines (177 loc) · 4.31 KB
/
index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./writer.css">
<title>Kirby Writer</title>
<style>
* {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
padding: 0;
margin: 0;
}
:root {
--padding: 2.5rem;
}
.writer {
height: 100%;
border: 0;
padding: var(--padding);
}
.writer:focus {
outline: none;
}
.layout {
display: grid;
}
.preview {
padding: .5rem;
white-space: pre-wrap;
background: #000;
color: #fff;
font-family: "SFMono-Regular", Consolas, Liberation Mono, Menlo, Courier, monospace;
margin: 0 var(--padding) var(--padding) var(--padding);
border-radius: 3px;
}
.github {
position: absolute;
top: 0;
right: 0;
display: none;
}
.toolbar {
position: absolute;
display: none;
border-radius: 3px;
background: #000;
color: #fff;
box-shadow: rgba(0, 0, 0, .25) 0 5px 10px;
}
.toolbar hr {
border: 0;
width: 1px;
background: rgba(255, 255, 255, .25);
}
.toolbar button {
border: 0;
background: none;
padding: .5rem;
color: currentColor;
cursor: pointer;
}
.toolbar button.active {
color: #7e9abf;
}
@media screen and (min-width: 60rem) {
:root {
--padding: 3rem;
}
.layout {
grid-template-columns: 1fr 1fr;
height: 100%;
}
.github {
display: block;
}
.preview {
min-height: 100%;
margin: 0;
border-radius: 0;
}
}
</style>
</head>
<body>
<main class="layout">
<div>
<div class="toolbar">
<button type="button" data-command="bold">B</button>
<button type="button" data-command="italic"><i>i</i></button>
<button type="button" data-command="strikeThrough"><del>S</del></button>
<hr>
<button type="button" data-command="code">Code</button>
<hr>
<button type="button" data-command="link"><u>Link</u></button>
</div>
<div class="writer"></div>
</div>
<code><pre class="preview"></pre></code>
</main>
<a class="github" href="https://github.com/getkirby/writer">
<img width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_white_ffffff.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1">
</a>
<script type="module">
import Toolbar from "./src/Toolbar.js";
import Writer from "./src/Writer.js";
const preview = document.querySelector(".preview");
/**
* Creates a new link
*/
const createLink = () => {
let href = null;
let link = writer.activeLink();
if (link) {
href = link.href;
}
const url = prompt("Please enter a URL", href || "");
if (url) {
writer.command("link", url);
} else if (url !== null) {
writer.command("unlink");
}
toolbar.hide();
};
/**
* Toolbar
*/
const toolbar = Toolbar(".toolbar", (command) => {
if (command === "link") {
createLink();
} else {
writer.command(command);
}
});
const updatePreview = () => {
preview.innerHTML = JSON.stringify(writer.toJson(), null, 4);
};
/**
* Writer instance
*/
window.writer = Writer(".writer", {
autofocus: true,
breaks: true,
onChange() {
updatePreview();
},
onMousedown() {
toolbar.hide();
},
onSelection() {
toolbar.activeFormats(writer.activeFormats());
},
onSelectionEnd() {
const rect = writer.selection.rect();
if (writer.selection.length() > 0) {
toolbar.show(rect);
} else {
toolbar.hide();
}
},
placeholder: "Start writing …",
shortcuts: {
"Meta+k": () => {
createLink();
}
},
});
/**
* Update the preview with the right
* document state after the writer gets
* initialized. This is only necessary
* for this demo or if you want to trigger
* the onChange event immediately.
*/
updatePreview();
</script>
</body>
</html>