Spaces:
Running
Running
Commit
·
1378e63
1
Parent(s):
4d0fc3b
add wrap button
Browse files- public/esltool.js +1 -1
- public/notebin.js +89 -68
public/esltool.js
CHANGED
|
@@ -149,7 +149,7 @@ for (const button of [askButton, correctBtn, translateBtn, explainBtn, defineBtn
|
|
| 149 |
|
| 150 |
setTimeout(() => {
|
| 151 |
utils.displayMarkdown(`
|
| 152 |
-
hello, this is note for language learner
|
| 153 |
code will display like this:
|
| 154 |
\`\`\`
|
| 155 |
this code \`\${value}\`
|
|
|
|
| 149 |
|
| 150 |
setTimeout(() => {
|
| 151 |
utils.displayMarkdown(`
|
| 152 |
+
hello, this is note app for language learner, press the blue circle then speak now! try ask button or ctrl + enter to send current line or selected text to AI
|
| 153 |
code will display like this:
|
| 154 |
\`\`\`
|
| 155 |
this code \`\${value}\`
|
public/notebin.js
CHANGED
|
@@ -43,22 +43,23 @@ function getCurrentLineString(element) {
|
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
-
function createLastButton(cmd, name = cmd) {
|
| 47 |
const button = document.createElement('button');
|
| 48 |
|
| 49 |
button.className = 'toastui-editor-toolbar-icons last';
|
| 50 |
button.style.backgroundImage = 'none';
|
| 51 |
-
button.style.margin = '0';
|
| 52 |
-
button.style.fontSize='x-large';
|
| 53 |
-
button.innerHTML =
|
| 54 |
button.addEventListener('click', () => {
|
| 55 |
-
|
|
|
|
| 56 |
});
|
| 57 |
|
| 58 |
return button;
|
| 59 |
}
|
| 60 |
|
| 61 |
-
let editorContainer=document.querySelector('#notebin_editor');
|
| 62 |
window.tuieditor = window.editor = new toastui.Editor({
|
| 63 |
el: document.querySelector('#notebin_editor'),
|
| 64 |
previewStyle: 'tab',
|
|
@@ -75,6 +76,26 @@ window.tuieditor = window.editor = new toastui.Editor({
|
|
| 75 |
el: createLastButton('redo', '⤻'),
|
| 76 |
command: 'redo',
|
| 77 |
tooltip: 'Redo'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
}
|
| 79 |
],
|
| 80 |
['heading'],
|
|
@@ -89,43 +110,43 @@ window.tuieditor = window.editor = new toastui.Editor({
|
|
| 89 |
});
|
| 90 |
|
| 91 |
setTimeout(() => {
|
| 92 |
-
|
| 93 |
-
// tuieditor.focus();
|
| 94 |
-
tuieditor.moveCursorToStart(true);
|
| 95 |
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
console.log('focus event triggered:', event);
|
| 99 |
-
syncNote();
|
| 100 |
-
});
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
window.tuieditor.mdEditor.el.addEventListener('keydown', function(event) {
|
| 104 |
-
if (event.key === 'Enter' && event.ctrlKey) {
|
| 105 |
-
// Your code here
|
| 106 |
-
let currentLineString=getCurrentLineString(editorContainer);
|
| 107 |
-
console.log('Ctrl + Enter was pressed:',currentLineString);
|
| 108 |
-
let prompt = ' ';
|
| 109 |
-
let selectText = window.getSelection().toString();
|
| 110 |
-
utils.displayMarkdown(`${prompt} **${selectText.length >= 1 ? selectText : currentLineString}** ...`);
|
| 111 |
-
utils.AIComplete(`${prompt} **${selectText.length >= 1 ? selectText : currentLineString}** `);
|
| 112 |
-
}
|
| 113 |
-
});
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
| 123 |
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
|
| 131 |
}, 1000);
|
|
@@ -159,22 +180,22 @@ const editorchange = new CustomEvent('editorchange', {
|
|
| 159 |
cancelable: true
|
| 160 |
});
|
| 161 |
|
| 162 |
-
document.addEventListener('editorchange', ()=>{
|
| 163 |
console.log('editorchange');
|
| 164 |
-
editorModel.lastChangeTime=Date.now();
|
| 165 |
syncNote();
|
| 166 |
-
|
| 167 |
})
|
| 168 |
|
| 169 |
-
let setChangeTimeoutid=0;
|
| 170 |
-
document.addEventListener('keydown', ()=>{
|
| 171 |
console.log('keydown');
|
| 172 |
clearTimeout(setChangeTimeoutid);
|
| 173 |
-
setChangeTimeoutid=setTimeout(() => {
|
| 174 |
-
|
| 175 |
|
| 176 |
}, 5000);
|
| 177 |
-
|
| 178 |
})
|
| 179 |
|
| 180 |
document.body.addEventListener('paste', (event) => {
|
|
@@ -214,9 +235,9 @@ console.log(noteid);
|
|
| 214 |
|
| 215 |
|
| 216 |
async function initEditorModel() {
|
| 217 |
-
editorModel.noteid= getUrlParameter('noteid') || Date.now();
|
| 218 |
setUrlParameter('noteid', editorModel.noteid);
|
| 219 |
-
console.log('initEditorModel',editorModel);
|
| 220 |
getNote();
|
| 221 |
|
| 222 |
}
|
|
@@ -230,14 +251,14 @@ setInterval(async () => {
|
|
| 230 |
}, 3000)
|
| 231 |
|
| 232 |
|
| 233 |
-
async function getNote(){
|
| 234 |
let res = await fetch(`/kv/get?key=${editorModel.noteid}`);
|
| 235 |
res = await res.json();
|
| 236 |
console.log('getNote:', res);
|
| 237 |
if (res) {
|
| 238 |
-
res=res.value;
|
| 239 |
editorModel.value = res.text;
|
| 240 |
-
editorModel.lastChangeTime=res.lastChangeTime || 0;
|
| 241 |
tuieditor.setMarkdown(res.text)
|
| 242 |
}
|
| 243 |
}
|
|
@@ -261,30 +282,30 @@ async function saveNote() {
|
|
| 261 |
}
|
| 262 |
|
| 263 |
|
| 264 |
-
async function syncNote(){
|
| 265 |
try {
|
| 266 |
let res = await fetch(`/kv/get?key=${editorModel.noteid}`);
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
}
|
| 278 |
-
|
| 279 |
-
saveNote();
|
| 280 |
-
}
|
| 281 |
-
}
|
| 282 |
-
|
| 283 |
} catch (error) {
|
| 284 |
-
console.log('syncNote eroor:',error);
|
| 285 |
-
saveNote();
|
| 286 |
}
|
| 287 |
-
|
| 288 |
}
|
| 289 |
|
| 290 |
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
+
function createLastButton(cmd, name = cmd, onclick = console.log,style={}) {
|
| 47 |
const button = document.createElement('button');
|
| 48 |
|
| 49 |
button.className = 'toastui-editor-toolbar-icons last';
|
| 50 |
button.style.backgroundImage = 'none';
|
| 51 |
+
button.style.margin = style.margin || '0';
|
| 52 |
+
button.style.fontSize = style.fontSize || 'x-large';
|
| 53 |
+
button.innerHTML = `${name}`;
|
| 54 |
button.addEventListener('click', () => {
|
| 55 |
+
onclick();
|
| 56 |
+
editor.exec(cmd || '');
|
| 57 |
});
|
| 58 |
|
| 59 |
return button;
|
| 60 |
}
|
| 61 |
|
| 62 |
+
let editorContainer = document.querySelector('#notebin_editor');
|
| 63 |
window.tuieditor = window.editor = new toastui.Editor({
|
| 64 |
el: document.querySelector('#notebin_editor'),
|
| 65 |
previewStyle: 'tab',
|
|
|
|
| 76 |
el: createLastButton('redo', '⤻'),
|
| 77 |
command: 'redo',
|
| 78 |
tooltip: 'Redo'
|
| 79 |
+
},
|
| 80 |
+
{
|
| 81 |
+
el: createLastButton('', 'wrap', () => {
|
| 82 |
+
const element = document.querySelector('.ProseMirror');
|
| 83 |
+
if (element.style.overflowX === 'auto' && element.style.whiteSpace === 'nowrap') {
|
| 84 |
+
element.style.overflowX = '';
|
| 85 |
+
element.style.whiteSpace = '';
|
| 86 |
+
} else {
|
| 87 |
+
element.style.overflowX = 'auto';
|
| 88 |
+
element.style.whiteSpace = 'nowrap';
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
},
|
| 92 |
+
{
|
| 93 |
+
fontSize: 'medium'
|
| 94 |
+
}
|
| 95 |
+
),
|
| 96 |
+
|
| 97 |
+
command: 'wrap',
|
| 98 |
+
tooltip: 'wrap'
|
| 99 |
}
|
| 100 |
],
|
| 101 |
['heading'],
|
|
|
|
| 110 |
});
|
| 111 |
|
| 112 |
setTimeout(() => {
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
// tuieditor.focus();
|
| 115 |
+
tuieditor.moveCursorToStart(true);
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
window.tuieditor.mdEditor.el.addEventListener('focus', (event) => {
|
| 118 |
+
// Log the event and the pasted data
|
| 119 |
+
console.log('focus event triggered:', event);
|
| 120 |
+
syncNote();
|
| 121 |
+
});
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
+
window.tuieditor.mdEditor.el.addEventListener('keydown', function (event) {
|
| 125 |
+
if (event.key === 'Enter' && event.ctrlKey) {
|
| 126 |
+
// Your code here
|
| 127 |
+
let currentLineString = getCurrentLineString(editorContainer);
|
| 128 |
+
console.log('Ctrl + Enter was pressed:', currentLineString);
|
| 129 |
+
let prompt = ' ';
|
| 130 |
+
let selectText = window.getSelection().toString();
|
| 131 |
+
utils.displayMarkdown(`${prompt} **${selectText.length >= 1 ? selectText : currentLineString}** ...`);
|
| 132 |
+
utils.AIComplete(`${prompt} **${selectText.length >= 1 ? selectText : currentLineString}** `);
|
| 133 |
+
}
|
| 134 |
+
});
|
| 135 |
|
| 136 |
+
document.body.addEventListener('keydown', event => {
|
| 137 |
+
if (event.key === 'Enter' && event.ctrlKey) {
|
| 138 |
+
// Your code here
|
| 139 |
+
tuieditor.mdEditor.focus();
|
| 140 |
|
| 141 |
+
console.log('body Ctrl + Enter was pressed:');
|
| 142 |
+
}
|
| 143 |
+
});
|
| 144 |
+
|
| 145 |
+
let url_div = document.querySelector('#url_div');
|
| 146 |
+
url_div.innerText = window.location.href;
|
| 147 |
+
url_div.addEventListener('click', () => {
|
| 148 |
+
url_div.scrollIntoView({ behavior: 'smooth' });
|
| 149 |
+
})
|
| 150 |
|
| 151 |
|
| 152 |
}, 1000);
|
|
|
|
| 180 |
cancelable: true
|
| 181 |
});
|
| 182 |
|
| 183 |
+
document.addEventListener('editorchange', () => {
|
| 184 |
console.log('editorchange');
|
| 185 |
+
editorModel.lastChangeTime = Date.now();
|
| 186 |
syncNote();
|
| 187 |
+
|
| 188 |
})
|
| 189 |
|
| 190 |
+
let setChangeTimeoutid = 0;
|
| 191 |
+
document.addEventListener('keydown', () => {
|
| 192 |
console.log('keydown');
|
| 193 |
clearTimeout(setChangeTimeoutid);
|
| 194 |
+
setChangeTimeoutid = setTimeout(() => {
|
| 195 |
+
document.body.dispatchEvent(editorchange)
|
| 196 |
|
| 197 |
}, 5000);
|
| 198 |
+
|
| 199 |
})
|
| 200 |
|
| 201 |
document.body.addEventListener('paste', (event) => {
|
|
|
|
| 235 |
|
| 236 |
|
| 237 |
async function initEditorModel() {
|
| 238 |
+
editorModel.noteid = getUrlParameter('noteid') || Date.now();
|
| 239 |
setUrlParameter('noteid', editorModel.noteid);
|
| 240 |
+
console.log('initEditorModel', editorModel);
|
| 241 |
getNote();
|
| 242 |
|
| 243 |
}
|
|
|
|
| 251 |
}, 3000)
|
| 252 |
|
| 253 |
|
| 254 |
+
async function getNote() {
|
| 255 |
let res = await fetch(`/kv/get?key=${editorModel.noteid}`);
|
| 256 |
res = await res.json();
|
| 257 |
console.log('getNote:', res);
|
| 258 |
if (res) {
|
| 259 |
+
res = res.value;
|
| 260 |
editorModel.value = res.text;
|
| 261 |
+
editorModel.lastChangeTime = res.lastChangeTime || 0;
|
| 262 |
tuieditor.setMarkdown(res.text)
|
| 263 |
}
|
| 264 |
}
|
|
|
|
| 282 |
}
|
| 283 |
|
| 284 |
|
| 285 |
+
async function syncNote() {
|
| 286 |
try {
|
| 287 |
let res = await fetch(`/kv/get?key=${editorModel.noteid}`);
|
| 288 |
+
res = await res.json();
|
| 289 |
+
console.log('getNote in syncNote:', res);
|
| 290 |
+
if (res) {
|
| 291 |
+
res = res.value;
|
| 292 |
+
if (res.lastChangeTime > editorModel.lastChangeTime) {
|
| 293 |
+
console.log(res.lastChangeTime, editorModel.lastChangeTime);
|
| 294 |
+
editorModel.value = res.text;
|
| 295 |
+
editorModel.lastChangeTime = res.lastChangeTime || 0;
|
| 296 |
+
tuieditor.setMarkdown(res.text);
|
| 297 |
|
| 298 |
+
}
|
| 299 |
+
else {
|
| 300 |
+
saveNote();
|
| 301 |
+
}
|
| 302 |
}
|
| 303 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
} catch (error) {
|
| 305 |
+
console.log('syncNote eroor:', error);
|
| 306 |
+
saveNote();
|
| 307 |
}
|
| 308 |
+
|
| 309 |
}
|
| 310 |
|
| 311 |
|