-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo.html
262 lines (238 loc) · 8.77 KB
/
Demo.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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<title>Squire Editor | Praveen Yadav</title>
<style type="text/css" media="screen">
body {
position: relative;
margin: 0 auto;
padding: 50px;
width: clamp(250px, 800px, 100vw);
font: 400 14px/1.24 helvetica, arial, sans-serif;
text-shadow: 0 1px 0 white;
}
h1 {
font-size: 1.95em;
}
img {
max-width: 100%;
}
#editor {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
min-height: 200px;
border: 1px solid #888;
padding: 1em;
background: transparent;
color: #2b2b2b;
font: 13px/1.35 Helvetica, arial, sans-serif;
cursor: text;
}
.editor-button-group {
display: flex;
flex-wrap: wrap;
row-gap: .2rem;
}
.editor-button-group button {
background-color: transparent;
border-radius: 10px;
padding: .2rem .5rem;
border-color: #ececec;
cursor: pointer;
}
a {
text-decoration: underline;
}
h2 {
font-size: 123.1%;
}
h3 {
font-size: 108%;
}
h1,
h2,
h3,
p {
margin: 1em 0;
}
h4,
h5,
h6 {
margin: 0;
}
ul,
ol {
margin: 0 1em;
padding: 0 1em;
}
blockquote {
border-left: 2px solid blue;
margin: 0;
padding: 0 10px;
}
pre {
white-space: pre-wrap;
word-wrap: break-word;
overflow-wrap: break-word;
border-radius: 3px;
border: 1px solid #ccc;
padding: 7px 10px;
background: #f6f6f6;
font-family: menlo, consolas, monospace;
font-size: 90%;
}
code {
border-radius: 3px;
border: 1px solid #ccc;
padding: 1px 3px;
background: #f6f6f6;
font-family: menlo, consolas, monospace;
font-size: 90%;
}
</style>
</head>
<body>
<h1>Squire Editor Demo</h1>
<header>
<p>Squire is a rich text editor primarily built for email apps by fastmail and modified by <a
href="https://github.com/pixiedevpraveen">me</a> for <a
href="https://github.com/pixiedevpraveen/pixie-notes">Pixie Notes</a> App. It’s designed to be integrated with
your own UI
framework, and so does not provide its own UI toolbar, widgets or overlays. This is a really simple demo, with
the most trivial of UI integrations, to show the raw component in action. <a
href="https://github.com/pixiedevpraveen/squire-editor">Learn more and see the source on GitHub</a>.</p>
<div class="editor-tools">
<p class="editor-button-group">
<button id="bold">Bold</button>
<button id="removeBold">Unbold</button>
<button id="italic">Italic</button>
<button id="removeItalic">Unitalic</button>
<button id="underline">Underline</button>
<button id="removeUnderline">Deunderline</button>
<button id="removeAllFormatting">Remove formatting</button>
<button id="setFontSize" class="prompt">Font size</button>
<button id="setFontFace" class="prompt">Font face</button>
</p>
<p class="editor-button-group">
<button id="setTextColor" class="prompt">Text color</button>
<button id="setHighlightColor" class="prompt">Text highlight</button>
<button id="makeLink" class="prompt">Link</button>
<button id="addDetectedLinks">Detect Link</button>
</p>
<p class="editor-button-group">
<button id="setTextAlignment" class="prompt">Align</button>
<button id="increaseQuoteLevel">Quote</button>
<button id="decreaseQuoteLevel">Dequote</button>
<button id="makeUnorderedList">List</button>
<button id="removeList">Unlist</button>
<button id="increaseListLevel">Increase list level</button>
<button id="decreaseListLevel">Decrease list level</button>
<button id="code">Code</button>
<button id="removeCode">Uncode</button>
<button id="insertImage" class="prompt">Insert image</button>
<button id="setHTML" class="prompt">Set HTML</button>
<button id="undo">Undo</button>
<button id="redo">Redo</button>
<button id="observe">Observe</button>
<button id="unobserve">Unobserve</button>
</p>
</div>
<div class="editor-detail">
<span>State: <strong id="editor-state"></strong></span>
<span>, Path: <strong id="editor-path"></strong></span>
</div>
</header>
<div id="editor">
<div class="paragraph"><b>sfddddddd</b><br></div>
<div class="paragraph">as<br></div>
<ul class="UL">
<li class="listItem">d<br></li>
<li class="listItem">as<br></li>
</ul>
<div class="paragraph pr-align-center" style="text-align: center;">sdasdad<br></div>
<div class="paragraph">https://github.com/pixiedevpraveen/squire-editor<br>
</div>
<div class="paragraph">as<br></div>
<div class="paragraph">d<br></div>
<div class="paragraph">a<br></div>
<div class="paragraph"><u>ssaassasa</u><br></div>
</div>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.4.3/purify.min.js" integrity="sha512-3dcbndbDLLWfKWevQu8C/1qVRcxx6h+eRDSnn3/pcBZHISRJgsj3u71U/Ad6nQVHrEi05hOSr6Hnb/p0pWc94w==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> -->
<script type="text/javascript" src="dist/squire-raw.js"></script>
<script type="module" charset="utf-8">
var editorEl = document.getElementById('editor');
const html = editorEl.innerHTML
console.log("before create");
var editor = new Squire(editorEl, {
blockTag: 'div',
classNames: {
align: "pr-align"
},
blockAttributes: { 'class': 'paragraph' },
sanitizeToDOMFragment: (h, e) => { /* console.log(h); */const el = document.createElement("div"); el.innerHTML = h; const d = document.createDocumentFragment(); d.append(...el.childNodes); return d },
tagAttributes: {
ul: { 'class': 'UL' },
ol: { 'class': 'OL' },
li: { 'class': 'listItem' },
a: { 'target': '_blank' },
pre: {
style: 'border-radius:3px;border:1px solid #ccc;padding:7px 10px;background:#f6f6f6;font-family:menlo,consolas,monospace;font-size:90%;white-space:pre-wrap;word-wrap:break-word;overflow-wrap:break-word;'
},
code: {
style: 'border-radius:3px;border:1px solid #ccc;padding:1px 3px;background:#f6f6f6;font-family:menlo,consolas,monospace;font-size:90%;'
},
}
});
editor.setHTML(html)
editor.addEventListener('undoStateChange', function (event) {
document.getElementById("editor-state").innerText = JSON.stringify(event.detail)
})
editor.addEventListener('pathChange', function (event) {
document.getElementById("editor-path").innerText = event.detail.path
})
editor.addEventListener('pasteImage', function (event) {
const items = [...event.detail.clipboardData.items];
const imageItems = items.filter((item) => /image/.test(item.type));
if (!imageItems.length) {
return false;
}
let reader = new FileReader();
reader.onload = (loadEvent) => {
this.insertImage(loadEvent.target.result);
}
reader.readAsDataURL(imageItems[0].getAsFile());
});
document.addEventListener('click', function (e) {
var id = e.target.id,
value;
if (id && editor) {
if (id === "enableEditor") {
editorEl.contentEditable = "true"
} else if (id === "disableEditor") {
editorEl.contentEditable = "false"
} else if (id === "addDetectedLinks") {
editor.forEachBlock((block) => {
editor[id](block);
}, true)
} else if (id in editor) {
if (e.target.className === 'prompt') {
value = prompt('Value:');
}
editor[id](value);
}
}
}, false);
</script>
</body>
</html>