[backend] fix: 修复异常处理和类型转换问题

This commit is contained in:
xsl
2026-01-26 11:53:40 +08:00
parent 7ccc2a6ac6
commit 83e05bf85f
28639 changed files with 2506458 additions and 93 deletions
+1
View File
@@ -0,0 +1 @@
node_modules
+18
View File
@@ -0,0 +1,18 @@
# Toggle Selection
Simple module exposing function that deselects current browser selection and returns function that restores selection.
```
var deselect = require('toggle-selection');
var reselect = deselect(); // remove all selection
// …
// do something with current selection, text, etc;
// …
reselect(); // restore selection
```
All credits go to [@shvaikalesh](https://github.com/shvaikalesh).
# [Example](https://github.com/sudodoki/toggle-selection/blob/master/example)
![example recording](http://g.recordit.co/YPu6mHvcKe.gif)
+16
View File
@@ -0,0 +1,16 @@
var selection = document.getSelection();
document.addEventListener('DOMContentLoaded', function(event) {
setTimeout(function() {
if (!selection.rangeCount) { // for demo purposes only
return;
}
reselect = module.exports();
setTimeout(function() {
reselect();
console.log('reselected');
}, 1000);
console.log('deselected');
}, 2000);
});
+26
View File
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Page</title>
<script src="../index.js"></script>
<script src="demo.js"></script>
</head>
<body>
<textarea cols="30" rows="10">Some random stuff.</textarea>
<textarea cols="30" rows="10">Some random stuff.</textarea>
<textarea cols="30" rows="10">Some random stuff.</textarea>
<div contentEditable>Some random stuff.</div>
<input value="Some random stuff.">
<p>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aenean commodo ligula eget dolor. Aenean massa.
Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem.
Nulla consequat massa quis enim.
Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.
In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo.
Nullam dictum felis eu pede mollis pretium. Integer tincidunt.
</p>
</body>
</html>
+39
View File
@@ -0,0 +1,39 @@
module.exports = function () {
var selection = document.getSelection();
if (!selection.rangeCount) {
return function () {};
}
var active = document.activeElement;
var ranges = [];
for (var i = 0; i < selection.rangeCount; i++) {
ranges.push(selection.getRangeAt(i));
}
switch (active.tagName.toUpperCase()) { // .toUpperCase handles XHTML
case 'INPUT':
case 'TEXTAREA':
active.blur();
break;
default:
active = null;
break;
}
selection.removeAllRanges();
return function () {
selection.type === 'Caret' &&
selection.removeAllRanges();
if (!selection.rangeCount) {
ranges.forEach(function(range) {
selection.addRange(range);
});
}
active &&
active.focus();
};
};
+27
View File
@@ -0,0 +1,27 @@
{
"name": "toggle-selection",
"version": "1.0.6",
"description": "Toggle current selected content in browser",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/sudodoki/toggle-selection"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"selection",
"toggle",
"browser",
"deselect"
],
"author": "sudodoki <smd.deluzion@gmail.com> (sudodoki.name)",
"license": "MIT",
"contributors": [
{
"name": "Aleksej Shvajka",
"url": "https://github.com/shvaikalesh"
}
]
}