mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 06:29:29 +01:00
fix theme loading in editor
This commit is contained in:
@@ -296,3 +296,144 @@ function attachEditorListeners() {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function attachMessageListener() {
|
||||||
|
titleInput = isTablet ? 'titleInput' : 'simpleTitleInput';
|
||||||
|
infoBar = isTablet ? '.info-bar' : '.info-bar-alt';
|
||||||
|
|
||||||
|
document.addEventListener('message', (data) => {
|
||||||
|
let message = JSON.parse(data.data);
|
||||||
|
let type = message.type;
|
||||||
|
let value;
|
||||||
|
if (message.value && message.type !== 'nomenu') {
|
||||||
|
value = message.value;
|
||||||
|
} else {
|
||||||
|
value = message.value;
|
||||||
|
}
|
||||||
|
switch (type) {
|
||||||
|
case 'reset': {
|
||||||
|
editor.history.clear();
|
||||||
|
editor.setText('', 'api');
|
||||||
|
document.getElementById(titleInput).value = '';
|
||||||
|
document.getElementById(titleInput).blur();
|
||||||
|
editor.blur();
|
||||||
|
document.getElementById(titleInput).blur();
|
||||||
|
window.blur();
|
||||||
|
|
||||||
|
info = document.querySelector(infoBar);
|
||||||
|
info.querySelector('#infodate').innerText = '';
|
||||||
|
info.querySelector('#infosaved').innerText = '';
|
||||||
|
info.querySelector('#infowords').innerText = '';
|
||||||
|
autosize();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'keyboard':
|
||||||
|
var range = editor.getSelection();
|
||||||
|
if (range) {
|
||||||
|
if (range.length == 0) {
|
||||||
|
var bounds = editor.getBounds(range.index, range.index);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
document
|
||||||
|
.querySelector('.app-main')
|
||||||
|
.scrollTo({top: bounds.top, behavior: 'smooth'});
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'blur':
|
||||||
|
document.getElementById(titleInput).blur();
|
||||||
|
editor.blur();
|
||||||
|
window.blur();
|
||||||
|
break;
|
||||||
|
case 'undo':
|
||||||
|
editor.history.undo();
|
||||||
|
break;
|
||||||
|
case 'redo':
|
||||||
|
editor.history.redo();
|
||||||
|
break;
|
||||||
|
case 'clearHistory':
|
||||||
|
editor.history.clear();
|
||||||
|
break;
|
||||||
|
case 'dateEdited':
|
||||||
|
linfo = document.querySelector(infoBar);
|
||||||
|
info.querySelector('#infodate').innerText = value;
|
||||||
|
break;
|
||||||
|
case 'saving':
|
||||||
|
info = document.querySelector(infoBar);
|
||||||
|
info.querySelector('#infosaved').innerText = value;
|
||||||
|
break;
|
||||||
|
case 'text':
|
||||||
|
editor.setText(value, 'api');
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
info = document.querySelector(infoBar);
|
||||||
|
info.querySelector('#infowords').innerText =
|
||||||
|
editor.getText().split(' ').length + ' words';
|
||||||
|
info.querySelector('#infosaved').innerText = 'Saved';
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'clearEditor':
|
||||||
|
editor.setText('', 'api');
|
||||||
|
break;
|
||||||
|
case 'clearTitle':
|
||||||
|
document.getElementById(titleInput).value = '';
|
||||||
|
break;
|
||||||
|
case 'focusEditor':
|
||||||
|
editor.focus();
|
||||||
|
break;
|
||||||
|
case 'focusTitle':
|
||||||
|
document.getElementById(titleInput).focus();
|
||||||
|
autosize();
|
||||||
|
break;
|
||||||
|
case 'nomenu':
|
||||||
|
let isenabled = value;
|
||||||
|
//let width = window.innerWidth;
|
||||||
|
let titleIn = document.getElementById('titlebar');
|
||||||
|
if (isenabled) {
|
||||||
|
//titleIn.style.width = width;
|
||||||
|
titleIn.style['padding-left'] = 12;
|
||||||
|
titleIn.style['padding-right'] = window.innerWidth * 0.4;
|
||||||
|
} else {
|
||||||
|
//titleIn.style.width = width - 120;
|
||||||
|
titleIn.style['padding-left'] = 60;
|
||||||
|
titleIn.style['padding-right'] = window.innerWidth * 0.4;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'title':
|
||||||
|
document.getElementById(titleInput).value = JSON.parse(data.data).value;
|
||||||
|
autosize();
|
||||||
|
break;
|
||||||
|
case 'theme':
|
||||||
|
pageTheme.colors = value;
|
||||||
|
setTheme();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'delta':
|
||||||
|
const content = value;
|
||||||
|
editor.setContents(content, 'api');
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
info = document.querySelector(infoBar);
|
||||||
|
info.querySelector('#infowords').innerText =
|
||||||
|
editor.getText().split(' ').length + ' words';
|
||||||
|
info.querySelector('#infosaved').innerText = 'Saved';
|
||||||
|
|
||||||
|
document.body.scrollTop = 0; // For Safari
|
||||||
|
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
|
||||||
|
}, 100);
|
||||||
|
autosize();
|
||||||
|
break;
|
||||||
|
case 'html':
|
||||||
|
editor.setContents(editor.clipboard.convert(value, 'api'), 'silent');
|
||||||
|
/* setTimeout(() => {
|
||||||
|
editor.setSelection(editor.getText().length - 1, 0);
|
||||||
|
}, 0); */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,14 +23,15 @@
|
|||||||
<div id="toolbar"></div>
|
<div id="toolbar"></div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script src="constants.js">
|
<script>
|
||||||
</script>
|
let editor;
|
||||||
<script src="module.js">
|
let isTablet = false;
|
||||||
</script>
|
</script>
|
||||||
<script src="quill.js">
|
<script src="quill.js"></script>
|
||||||
</script>
|
<script src="constants.js"></script>
|
||||||
<script src="listeners.js">
|
<script src="module.js"></script>
|
||||||
</script>
|
<script src="magic-url.js"></script>
|
||||||
|
<script src="listeners.js"></script>
|
||||||
<script src="image-resize.min.js"></script>
|
<script src="image-resize.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
@@ -60,11 +60,10 @@
|
|||||||
let isTablet = false;
|
let isTablet = false;
|
||||||
</script>
|
</script>
|
||||||
<script src="quill.js"></script>
|
<script src="quill.js"></script>
|
||||||
|
<script src="constants.js"></script>
|
||||||
<script src="module.js"></script>
|
<script src="module.js"></script>
|
||||||
<script src="magic-url.js"></script>
|
<script src="magic-url.js"></script>
|
||||||
<script src="constants.js"></script>
|
|
||||||
<script src="listeners.js"></script>
|
<script src="listeners.js"></script>
|
||||||
|
|
||||||
<script src="image-resize.min.js"></script>
|
<script src="image-resize.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -446,7 +445,7 @@
|
|||||||
this.quill.format("script", value, "user");
|
this.quill.format("script", value, "user");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
attachMessageListener();
|
||||||
function loadAction(premium, tab) {
|
function loadAction(premium, tab) {
|
||||||
isTablet = tab;
|
isTablet = tab;
|
||||||
setFonts();
|
setFonts();
|
||||||
@@ -515,9 +514,9 @@
|
|||||||
Quill.register(Font, true);
|
Quill.register(Font, true);
|
||||||
|
|
||||||
attachTitleInputListeners();
|
attachTitleInputListeners();
|
||||||
setTheme();
|
|
||||||
attachEditorListeners();
|
attachEditorListeners();
|
||||||
fixDropdownMenuLocations();
|
fixDropdownMenuLocations();
|
||||||
|
setTheme();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -475,7 +475,7 @@
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
attachMessageListener();
|
||||||
function loadAction(premium, tab) {
|
function loadAction(premium, tab) {
|
||||||
isTablet = tab;
|
isTablet = tab;
|
||||||
let titleIn = document.getElementById('titlebar');
|
let titleIn = document.getElementById('titlebar');
|
||||||
@@ -550,9 +550,9 @@
|
|||||||
|
|
||||||
addLinkMatcher();
|
addLinkMatcher();
|
||||||
attachTitleInputListeners();
|
attachTitleInputListeners();
|
||||||
setTheme();
|
|
||||||
attachEditorListeners();
|
attachEditorListeners();
|
||||||
fixDropdownMenuLocations();
|
fixDropdownMenuLocations();
|
||||||
|
setTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -85,6 +85,88 @@ function attachEditorListeners() {
|
|||||||
titleInput = isTablet ? 'titleInput' : 'simpleTitleInput';
|
titleInput = isTablet ? 'titleInput' : 'simpleTitleInput';
|
||||||
infoBar = isTablet ? '.info-bar' : '.info-bar-alt';
|
infoBar = isTablet ? '.info-bar' : '.info-bar-alt';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function isWhitespace(ch) {
|
||||||
|
let whiteSpace = false;
|
||||||
|
if (ch === ' ' || ch === '\t' || ch === '\n') {
|
||||||
|
whiteSpace = true;
|
||||||
|
}
|
||||||
|
return whiteSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
let deltaTimeout = null;
|
||||||
|
let historyTimeout = null;
|
||||||
|
|
||||||
|
editor.on('text-change', function (delta, oldDelta, source) {
|
||||||
|
var regex = /https?:\/\/[^\s]+$/;
|
||||||
|
if (source === 'api') return;
|
||||||
|
if (
|
||||||
|
delta.ops.length === 2 &&
|
||||||
|
delta.ops[0].retain &&
|
||||||
|
isWhitespace(delta.ops[1].insert)
|
||||||
|
) {
|
||||||
|
var endRetain = delta.ops[0].retain;
|
||||||
|
var text = editor.getText().substr(0, endRetain);
|
||||||
|
var match = text.toLowerCase().match(regex);
|
||||||
|
|
||||||
|
if (match !== null) {
|
||||||
|
var url = match[0];
|
||||||
|
|
||||||
|
var ops = [];
|
||||||
|
if (endRetain > url.length) {
|
||||||
|
ops.push({retain: endRetain - url.length});
|
||||||
|
}
|
||||||
|
|
||||||
|
ops = ops.concat([
|
||||||
|
{delete: url.length},
|
||||||
|
{insert: url, attributes: {link: url}},
|
||||||
|
]);
|
||||||
|
|
||||||
|
editor.updateContents({
|
||||||
|
ops: ops,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
info = document.querySelector(infoBar);
|
||||||
|
let infowords = info.querySelector('#infowords');
|
||||||
|
if (infowords) {
|
||||||
|
infowords.innerText =
|
||||||
|
editor.getText().split(' ').length + ' words';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deltaTimeout) {
|
||||||
|
clearTimeout(deltaTimeout);
|
||||||
|
deltaTimeout = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
deltaTimeout = setTimeout(() => {
|
||||||
|
let msg = JSON.stringify({
|
||||||
|
data: editor.getContents().ops,
|
||||||
|
type: 'delta',
|
||||||
|
});
|
||||||
|
window.ReactNativeWebView.postMessage(msg);
|
||||||
|
}, 50);
|
||||||
|
|
||||||
|
if (historyTimeout) {
|
||||||
|
clearTimeout(historyTimeout);
|
||||||
|
historyTimeout = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
historyTimeout = setTimeout(() => {
|
||||||
|
let history = JSON.stringify({
|
||||||
|
type: 'history',
|
||||||
|
undo: editor.history.stack.undo.length,
|
||||||
|
redo: editor.history.stack.redo.length,
|
||||||
|
});
|
||||||
|
window.ReactNativeWebView.postMessage(history);
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function attachMessageListener() {
|
||||||
|
titleInput = isTablet ? 'titleInput' : 'simpleTitleInput';
|
||||||
|
infoBar = isTablet ? '.info-bar' : '.info-bar-alt';
|
||||||
window.addEventListener('message', (data) => {
|
window.addEventListener('message', (data) => {
|
||||||
let message = JSON.parse(data.data);
|
let message = JSON.parse(data.data);
|
||||||
let type = message.type;
|
let type = message.type;
|
||||||
@@ -219,80 +301,4 @@ function attachEditorListeners() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function isWhitespace(ch) {
|
|
||||||
let whiteSpace = false;
|
|
||||||
if (ch === ' ' || ch === '\t' || ch === '\n') {
|
|
||||||
whiteSpace = true;
|
|
||||||
}
|
|
||||||
return whiteSpace;
|
|
||||||
}
|
|
||||||
|
|
||||||
let deltaTimeout = null;
|
|
||||||
let historyTimeout = null;
|
|
||||||
|
|
||||||
editor.on('text-change', function (delta, oldDelta, source) {
|
|
||||||
var regex = /https?:\/\/[^\s]+$/;
|
|
||||||
if (source === 'api') return;
|
|
||||||
if (
|
|
||||||
delta.ops.length === 2 &&
|
|
||||||
delta.ops[0].retain &&
|
|
||||||
isWhitespace(delta.ops[1].insert)
|
|
||||||
) {
|
|
||||||
var endRetain = delta.ops[0].retain;
|
|
||||||
var text = editor.getText().substr(0, endRetain);
|
|
||||||
var match = text.toLowerCase().match(regex);
|
|
||||||
|
|
||||||
if (match !== null) {
|
|
||||||
var url = match[0];
|
|
||||||
|
|
||||||
var ops = [];
|
|
||||||
if (endRetain > url.length) {
|
|
||||||
ops.push({retain: endRetain - url.length});
|
|
||||||
}
|
|
||||||
|
|
||||||
ops = ops.concat([
|
|
||||||
{delete: url.length},
|
|
||||||
{insert: url, attributes: {link: url}},
|
|
||||||
]);
|
|
||||||
|
|
||||||
editor.updateContents({
|
|
||||||
ops: ops,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
info = document.querySelector(infoBar);
|
|
||||||
let infowords = info.querySelector('#infowords');
|
|
||||||
if (infowords) {
|
|
||||||
infowords.innerText =
|
|
||||||
editor.getText().split(' ').length + ' words';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deltaTimeout) {
|
|
||||||
clearTimeout(deltaTimeout);
|
|
||||||
deltaTimeout = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
deltaTimeout = setTimeout(() => {
|
|
||||||
let msg = JSON.stringify({
|
|
||||||
data: editor.getContents().ops,
|
|
||||||
type: 'delta',
|
|
||||||
});
|
|
||||||
window.ReactNativeWebView.postMessage(msg);
|
|
||||||
}, 50);
|
|
||||||
|
|
||||||
if (historyTimeout) {
|
|
||||||
clearTimeout(historyTimeout);
|
|
||||||
historyTimeout = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
historyTimeout = setTimeout(() => {
|
|
||||||
let history = JSON.stringify({
|
|
||||||
type: 'history',
|
|
||||||
undo: editor.history.stack.undo.length,
|
|
||||||
redo: editor.history.stack.redo.length,
|
|
||||||
});
|
|
||||||
window.ReactNativeWebView.postMessage(history);
|
|
||||||
}, 1000);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,15 +22,19 @@
|
|||||||
<div id="editor"></div>
|
<div id="editor"></div>
|
||||||
<div id="toolbar"></div>
|
<div id="toolbar"></div>
|
||||||
</body>
|
</body>
|
||||||
|
<script>
|
||||||
<script src="constants.js"></script>
|
let editor;
|
||||||
<script src="listeners.js"></script>
|
let isTablet = false;
|
||||||
<script src="module.js"></script>
|
</script>
|
||||||
<script src="quill.js"></script>
|
<script src="quill.js"></script>
|
||||||
|
<script src="constants.js"></script>
|
||||||
|
<script src="module.js"></script>
|
||||||
|
<script src="magic-url.js"></script>
|
||||||
|
<script src="listeners.js"></script>
|
||||||
<script src="image-resize.min.js"></script>
|
<script src="image-resize.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
let editor;
|
let editor;
|
||||||
|
attachMessageListener();
|
||||||
function loadAction() {
|
function loadAction() {
|
||||||
|
|
||||||
setFonts();
|
setFonts();
|
||||||
@@ -66,8 +70,6 @@
|
|||||||
setTheme();
|
setTheme();
|
||||||
attachEditorListeners();
|
attachEditorListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAction()
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user