hi-mention
Advanced tools
Comparing version 2.2.1 to 2.2.2
{ | ||
"name": "hi-mention", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"main": "index", | ||
@@ -5,0 +5,0 @@ "types": "index.d.ts", |
@@ -261,5 +261,26 @@ # Mention 提及 | ||
```html | ||
v2.2.1 2024-10-27 - 修复长按删除键导致的光标丢失 v2.2.0 2024-10-27 - 对v2.1.0版本BUG继续修复 v2.1.0 2024-10-26 - 修复剪切、复制、粘贴 - 修复移动光标 - 修复换行 - 修复删除 - 修复焦点 - 修复占位符展示异常 - 针对火狐浏览器做兼容处理 v2.0.1 | ||
2024-10-25 - 修复默认用户选择器切换用户异常 v2.0.0 2024-10-25 - 初始版本 | ||
``` | ||
v2.2.2 2024-10-27 | ||
- 修复选择删除BUG | ||
v2.2.1 2024-10-27 | ||
- 修复长按删除键导致的光标丢失 | ||
v2.2.0 2024-10-27 | ||
- 对 v2.1.0 版本 BUG 继续修复 | ||
v2.1.0 2024-10-26 | ||
- 修复剪切、复制、粘贴 | ||
- 修复移动光标 | ||
- 修复换行 | ||
- 修复删除 | ||
- 修复焦点 | ||
- 修复占位符展示异常 | ||
- 针对火狐浏览器做兼容处理 | ||
v2.0.1 2024-10-25 | ||
- 修复默认用户选择器切换用户异常 | ||
v2.0.0 2024-10-25 | ||
- 重写 | ||
``` |
@@ -13,2 +13,3 @@ import { MentionOptions, UserSelectorOptions } from "./types"; | ||
export declare const TEXT_TAG_CLASS = "hi-mention-text"; | ||
export declare const USER_AT_CLASS = "hi-mention-at-user"; | ||
export declare const PLACEHOLDER_TEXT = "\uFEFF"; | ||
@@ -15,0 +16,0 @@ export declare const NEW_LINE: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultMentionOptions = exports.defaultUserSelectorOptions = exports.NEW_LINE = exports.PLACEHOLDER_TEXT = exports.TEXT_TAG_CLASS = exports.ROW_TAG_CLASS = exports.EDITOR_CLASS = exports.BROWSER = void 0; | ||
exports.defaultMentionOptions = exports.defaultUserSelectorOptions = exports.NEW_LINE = exports.PLACEHOLDER_TEXT = exports.USER_AT_CLASS = exports.TEXT_TAG_CLASS = exports.ROW_TAG_CLASS = exports.EDITOR_CLASS = exports.BROWSER = void 0; | ||
// 浏览器类型 | ||
@@ -23,2 +23,4 @@ var BROWSER = function () { | ||
exports.TEXT_TAG_CLASS = "hi-mention-text"; | ||
// @用户标签类名 | ||
exports.USER_AT_CLASS = "hi-mention-at-user"; | ||
// 占位符 | ||
@@ -25,0 +27,0 @@ exports.PLACEHOLDER_TEXT = "\uFEFF"; |
@@ -241,2 +241,3 @@ "use strict"; | ||
return this.closeUserSelector(); | ||
var range = (0, range_1.getRangeAt)(0, selection); | ||
var text = selection.anchorNode.textContent.slice(0, selection.anchorOffset); | ||
@@ -251,3 +252,2 @@ var trigger = this.options.trigger; | ||
this._inputSelection = selection; | ||
var range = (0, range_1.getRangeAt)(0, selection); | ||
if (!range) | ||
@@ -422,13 +422,16 @@ return; | ||
return this; | ||
var _c = this.options, nameKey = _c.nameKey, idKey = _c.idKey; | ||
var _c = this.options, nameKey = _c.nameKey, idKey = _c.idKey, pingyinKey = _c.pingyinKey, avatarKey = _c.avatarKey; | ||
// 创建一个span元素来表示用户 | ||
var span = (0, index_1.createElement)("span", { | ||
className: "hi-mention-at-user", | ||
className: const_1.USER_AT_CLASS, | ||
content: "@".concat(user[nameKey]), | ||
style: { | ||
color: this.options.mentionColor, | ||
cursor: "pointer", | ||
}, | ||
style: { color: this.options.mentionColor }, | ||
}); | ||
span.setAttribute("data-user-id", user[idKey]); | ||
span.setAttribute("data-user-id-type", typeof user[idKey]); | ||
span.setAttribute("data-user-name", user[nameKey]); | ||
if (user[avatarKey]) | ||
span.setAttribute("data-user-avatar", user[avatarKey]); | ||
if (user[pingyinKey]) | ||
span.setAttribute("data-user-pingyin", user[pingyinKey]); | ||
var range = this._inputRange; | ||
@@ -532,10 +535,21 @@ // 将光标重新设置到输入框中 | ||
Mention.prototype.getMentions = function () { | ||
var nodes = this._editorEl.querySelectorAll(".hi-mention-at-user"); | ||
var _a = this.options, users = _a.users, idKey = _a.idKey; | ||
return Array.from(nodes) | ||
.map(function (node) { | ||
var nodes = this._editorEl.querySelectorAll(".".concat(const_1.USER_AT_CLASS)); | ||
var _a = this.options, nameKey = _a.nameKey, idKey = _a.idKey, avatarKey = _a.avatarKey, pingyinKey = _a.pingyinKey; | ||
return Array.from(nodes).map(function (node) { | ||
var _a; | ||
var id = node.getAttribute("data-user-id"); | ||
return users.find(function (user) { return String(user[idKey]) === String(id); }); | ||
}) | ||
.filter(Boolean); | ||
var name = node.getAttribute("data-user-name"); | ||
var avatar = node.getAttribute("data-user-avatar"); | ||
var pingyin = node.getAttribute("data-user-pingyin"); | ||
var idType = node.getAttribute("data-user-id-type"); | ||
var user = (_a = {}, | ||
_a[idKey] = idType === "number" ? Number(id) : id, | ||
_a[nameKey] = name, | ||
_a); | ||
if (avatar) | ||
user[avatarKey] = avatar; | ||
if (pingyin) | ||
user[pingyinKey] = pingyin; | ||
return user; | ||
}); | ||
}; | ||
@@ -542,0 +556,0 @@ Mention.prototype.initUserSelector = function () { |
@@ -154,4 +154,5 @@ "use strict"; | ||
// 如果不在行内,则将当前光标所在的内容全部转移到新的一行 | ||
var textContent = rangeEl.textContent; | ||
if (rangeEl.className !== const_1.EDITOR_CLASS) { | ||
var textContent = ""; | ||
if (rangeEl.className !== const_1.EDITOR_CLASS && rangeEl.className !== const_1.ROW_TAG_CLASS) { | ||
textContent = rangeEl.textContent || ""; | ||
rangeEl.remove(); | ||
@@ -174,8 +175,16 @@ } | ||
} | ||
rangeIndex = which === "start" ? 0 : rowEl.childNodes.length; | ||
if (which === "start") { | ||
rangeIndex = 0; | ||
moveRangeAtRowStart(range, rowEl, false); | ||
} | ||
else { | ||
rangeIndex = rowEl.childNodes.length; | ||
moveRangeAtRowEnd(range, rowEl, which === "common"); | ||
} | ||
} | ||
if (!textEl || textEl.nodeName === "#text") { | ||
// 如果不在行内,则将当前光标所在的内容全部转移到新的一行 | ||
var textContent = rangeEl.textContent; | ||
if (rangeEl.className !== const_1.EDITOR_CLASS) { | ||
var textContent = ""; | ||
if (rangeEl.className !== const_1.EDITOR_CLASS && rangeEl.className !== const_1.ROW_TAG_CLASS) { | ||
textContent = rangeEl.textContent || ""; | ||
rangeEl.remove(); | ||
@@ -185,3 +194,10 @@ } | ||
rowEl.appendChild(textEl); | ||
rangeIndex = which === "start" ? 0 : rowEl.childNodes.length; | ||
if (which === "start") { | ||
rangeIndex = 0; | ||
moveRangeAtRowStart(range, rowEl, false); | ||
} | ||
else { | ||
rangeIndex = rowEl.childNodes.length; | ||
moveRangeAtRowEnd(range, rowEl, which === "common"); | ||
} | ||
} | ||
@@ -191,3 +207,3 @@ var _while = 0; // 防止死循环 | ||
if (which === "start") { | ||
textEl = textEl.previousElementSibling; | ||
textEl = (textEl.previousElementSibling ? textEl.previousElementSibling : textEl); | ||
var textNode_1 = textEl.lastChild; | ||
@@ -197,3 +213,3 @@ range.setStart(textNode_1 ? textNode_1 : textEl, (textNode_1 ? (_b = textNode_1.textContent) === null || _b === void 0 ? void 0 : _b.length : textEl.childNodes.length) || 0); | ||
else { | ||
textEl = textEl.nextElementSibling; | ||
textEl = (textEl.nextElementSibling ? textEl.nextElementSibling : textEl); | ||
var textNode_2 = textEl.firstChild; | ||
@@ -200,0 +216,0 @@ range.setEnd(textNode_2 ? textNode_2 : textEl, 0); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
110706
2528
286