to:sync
This commit is contained in:
parent
9f8817cf98
commit
dbd5c1caff
@ -23,7 +23,7 @@ export class MyBiz {
|
|||||||
newParagraph.setAttribute("id", uuid)
|
newParagraph.setAttribute("id", uuid)
|
||||||
newParagraph.setAttribute("data-order", curOrder)
|
newParagraph.setAttribute("data-order", curOrder)
|
||||||
newParagraph.onkeydown = window.myEdit.eventListener.KeydownListener
|
newParagraph.onkeydown = window.myEdit.eventListener.KeydownListener
|
||||||
newParagraph.innerHTML = "<br>"
|
// newParagraph.innerHTML = "<br>"
|
||||||
//添加一行
|
//添加一行
|
||||||
window.myEdit.utils.AddNewParagraph(newParagraph);
|
window.myEdit.utils.AddNewParagraph(newParagraph);
|
||||||
}
|
}
|
||||||
@ -247,46 +247,58 @@ export class MyBiz {
|
|||||||
let curP = window.myEdit.utils.GetEventTarget(event);
|
let curP = window.myEdit.utils.GetEventTarget(event);
|
||||||
let myDocItem = new MyDocItem(curP);
|
let myDocItem = new MyDocItem(curP);
|
||||||
let inputLength = curP.innerText.length
|
let inputLength = curP.innerText.length
|
||||||
|
console.log("emptyKeyWorkHandler :", curP, " _'", curP.innerHTML, "'_'", curP.innerText, "'_",
|
||||||
|
"\neq00", curP.innerHTML.startsWith(" # "),
|
||||||
|
"\neq01", curP.innerHTML.startsWith(" # "),
|
||||||
|
"\neq1", curP.innerText.startsWith("# "),
|
||||||
|
"\neq2", curP.innerText.startsWith("#"),
|
||||||
|
"\neq3", curP.innerHTML.startsWith("# "),
|
||||||
|
"\neq4", curP.innerHTML.startsWith("# "))
|
||||||
/**
|
/**
|
||||||
* h1 ~ h6
|
* h1 ~ h6
|
||||||
*/
|
*/
|
||||||
if (curP.innerText.startsWith("#") && curP.innerHTML.endsWith(" ")) {
|
if (curP.innerText.startsWith("#")) {
|
||||||
let curNo = myDocItem.parseOrder();
|
let curNo = myDocItem.parseOrder();
|
||||||
let mapNode = window.myEdit.ctx.MyDocMap.get(curNo);
|
let mapNode = window.myEdit.ctx.MyDocMap.get(curNo);
|
||||||
|
if (curP.innerHTML.startsWith("######")) {
|
||||||
// console.log(curP, " - ", curP.innerHTML, curP.innerHTML.startsWith("# "))
|
|
||||||
if (curP.innerHTML.startsWith("# ") || curP.innerHTML.startsWith("# ")) {
|
|
||||||
mapNode.getStyle().setNodeType("h1")
|
|
||||||
this.becomeAnotherElement(curP, "h1", onkeydownHandle)
|
|
||||||
} else if (curP.innerHTML.startsWith("## ")) {
|
|
||||||
mapNode.getStyle().setNodeType("h2")
|
|
||||||
this.becomeAnotherElement(curP, "h2", onkeydownHandle)
|
|
||||||
} else if (curP.innerHTML.startsWith("### ")) {
|
|
||||||
mapNode.getStyle().setNodeType("h3")
|
|
||||||
this.becomeAnotherElement(curP, "h3", onkeydownHandle)
|
|
||||||
} else if (curP.innerHTML.startsWith("#### ")) {
|
|
||||||
mapNode.getStyle().setNodeType("h4")
|
|
||||||
this.becomeAnotherElement(curP, "h4", onkeydownHandle)
|
|
||||||
} else if (curP.innerHTML.startsWith("##### ")) {
|
|
||||||
mapNode.getStyle().setNodeType("h5")
|
|
||||||
this.becomeAnotherElement(curP, "h5", onkeydownHandle)
|
|
||||||
} else {
|
|
||||||
mapNode.getStyle().setNodeType("h6")
|
mapNode.getStyle().setNodeType("h6")
|
||||||
this.becomeAnotherElement(curP, "h6", onkeydownHandle)
|
curP.innerHTML=curP.innerHTML.replace("######","")
|
||||||
|
this.becomeAnotherElement(curP, "h6")
|
||||||
|
} else if (curP.innerHTML.startsWith("#####")) {
|
||||||
|
mapNode.getStyle().setNodeType("h5")
|
||||||
|
curP.innerHTML=curP.innerHTML.replace("#####","")
|
||||||
|
this.becomeAnotherElement(curP, "h5")
|
||||||
|
} else if (curP.innerHTML.startsWith("####")) {
|
||||||
|
mapNode.getStyle().setNodeType("h4")
|
||||||
|
curP.innerHTML=curP.innerHTML.replace("####","")
|
||||||
|
this.becomeAnotherElement(curP, "h4")
|
||||||
|
} else if (curP.innerHTML.startsWith("###")) {
|
||||||
|
mapNode.getStyle().setNodeType("h3")
|
||||||
|
curP.innerHTML=curP.innerHTML.replace("###","")
|
||||||
|
this.becomeAnotherElement(curP, "h3")
|
||||||
|
} else if (curP.innerHTML.startsWith("##")) {
|
||||||
|
mapNode.getStyle().setNodeType("h2")
|
||||||
|
curP.innerHTML=curP.innerHTML.replace("##","")
|
||||||
|
this.becomeAnotherElement(curP, "h2")
|
||||||
|
} else {
|
||||||
|
mapNode.getStyle().setNodeType("h1")
|
||||||
|
curP.innerHTML=curP.innerHTML.replace("#","")
|
||||||
|
this.becomeAnotherElement(curP, "h1")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 无序列表效果
|
* 无序列表效果
|
||||||
*/
|
*/
|
||||||
if (inputLength === 2 && curP.innerText.startsWith("-") && curP.innerHTML.endsWith(" ")) {
|
if (curP.innerText.startsWith("-")) {
|
||||||
let curNo = myDocItem.parseOrder();
|
let curNo = myDocItem.parseOrder();
|
||||||
let mapNode = window.myEdit.ctx.MyDocMap.get(curNo);
|
let mapNode = window.myEdit.ctx.MyDocMap.get(curNo);
|
||||||
mapNode.getStyle().setPreStyle("ul", true)
|
mapNode.getStyle().setPreStyle("ul", true)
|
||||||
|
|
||||||
//clean
|
//clean
|
||||||
curP.innerHTML = ""
|
let historyContent = curP.innerHTML.replace("-", "");
|
||||||
mapNode.setSource("")
|
curP.innerHTML = historyContent
|
||||||
|
mapNode.setSource(curP.innerText)
|
||||||
|
|
||||||
//根据上一层级元素动态选择 todo
|
//根据上一层级元素动态选择 todo
|
||||||
curP.setAttribute("style", "padding-left: 1rem;")
|
curP.setAttribute("style", "padding-left: 1rem;")
|
||||||
@ -297,12 +309,6 @@ export class MyBiz {
|
|||||||
newParagraph.innerHTML = "∙ "
|
newParagraph.innerHTML = "∙ "
|
||||||
curP.append(newParagraph)
|
curP.append(newParagraph)
|
||||||
|
|
||||||
//添加一个选区
|
|
||||||
var selObj = window.myEdit.utils.GetSelection();
|
|
||||||
var rangeObj = document.createRange()
|
|
||||||
rangeObj.selectNode(curP)
|
|
||||||
selObj.addRange(rangeObj)
|
|
||||||
|
|
||||||
//收起选区到一个点,光标落在一个可编辑元素上
|
//收起选区到一个点,光标落在一个可编辑元素上
|
||||||
window.myEdit.utils.GetSelection().collapse(curP, true)
|
window.myEdit.utils.GetSelection().collapse(curP, true)
|
||||||
}
|
}
|
||||||
@ -310,7 +316,8 @@ export class MyBiz {
|
|||||||
/**
|
/**
|
||||||
* 有序列表效果
|
* 有序列表效果
|
||||||
*/
|
*/
|
||||||
if (inputLength > 2 && inputLength <= 5 && isNum(curP.innerText.substring(0, inputLength - 2)) && curP.innerHTML.endsWith(". ")) {
|
let preContent = curP.innerText.split(" ")[0]
|
||||||
|
if (window.myEdit.utils.IsNum(preContent)) {
|
||||||
let num = curP.innerText.substring(0, inputLength - 2)
|
let num = curP.innerText.substring(0, inputLength - 2)
|
||||||
console.log(curP.innerText, num)
|
console.log(curP.innerText, num)
|
||||||
|
|
||||||
@ -319,8 +326,9 @@ export class MyBiz {
|
|||||||
mapNode.getStyle().setPreStyle("ol", num)
|
mapNode.getStyle().setPreStyle("ol", num)
|
||||||
|
|
||||||
//clean
|
//clean
|
||||||
curP.innerHTML = ""
|
let historyContent = curP.innerHTML.replace("-", "");
|
||||||
mapNode.setSource("")
|
curP.innerHTML = historyContent
|
||||||
|
mapNode.setSource(curP.innerText)
|
||||||
//todo
|
//todo
|
||||||
curP.setAttribute("style", "padding-left: 1rem;")
|
curP.setAttribute("style", "padding-left: 1rem;")
|
||||||
//新增元素
|
//新增元素
|
||||||
@ -340,29 +348,30 @@ export class MyBiz {
|
|||||||
* 变成另一个元素
|
* 变成另一个元素
|
||||||
* @param {*} elementName
|
* @param {*} elementName
|
||||||
*/
|
*/
|
||||||
becomeAnotherElement(elementName) {
|
becomeAnotherElement(curP, elementName) {
|
||||||
let newParagraph = document.createElement(elementName)
|
let newParagraph = document.createElement(elementName)
|
||||||
newParagraph.setAttribute("contenteditable", "true")
|
newParagraph.setAttribute("contenteditable", "true")
|
||||||
newParagraph.setAttribute("data-id", this.self.getAttribute("data-id"))
|
newParagraph.setAttribute("data-id", curP.getAttribute("data-id"))
|
||||||
newParagraph.setAttribute("id", this.self.getAttribute("data-id"))
|
newParagraph.setAttribute("id", curP.getAttribute("data-id"))
|
||||||
newParagraph.setAttribute("data-order", this.self.getAttribute("data-order"))
|
newParagraph.setAttribute("data-order", curP.getAttribute("data-order"))
|
||||||
newParagraph.onkeydown = onkeydownHandle
|
newParagraph.onkeydown = window.myEdit.eventListener.KeydownListener
|
||||||
|
|
||||||
//todo 支持 有数据的行 在行首输入 #
|
//todo 支持 有数据的行 在行首输入 #
|
||||||
// if()
|
// if()
|
||||||
// switch (elementName){
|
// switch (elementName){
|
||||||
// case "h1":
|
// case "h1":
|
||||||
// }
|
// }
|
||||||
newParagraph.innerHTML = "<br>"
|
newParagraph.innerHTML = curP.innerHTML
|
||||||
|
|
||||||
window.myEdit.utils.InsertAfter(newParagraph, this.self)
|
window.myEdit.utils.InsertAfter(curP, newParagraph)
|
||||||
this.self.remove();
|
curP.remove();
|
||||||
this.self = newParagraph;
|
curP = newParagraph;
|
||||||
|
|
||||||
//matData
|
//matData
|
||||||
let curNo = parseOrder(this.self)
|
let myP = new MyDocItem(curP);
|
||||||
let mapNode = utils.MyDocMap.get(curNo)
|
let curNo = myP.parseOrder();
|
||||||
mapNode.setSource("")
|
let mapNode = window.myEdit.ctx.getMapItem(curNo)
|
||||||
|
mapNode.setSource(curP.innerText)
|
||||||
|
|
||||||
//收起选区到一个点,光标落在一个可编辑元素上
|
//收起选区到一个点,光标落在一个可编辑元素上
|
||||||
window.myEdit.utils.GetSelection().setPosition(newParagraph, 0)
|
window.myEdit.utils.GetSelection().setPosition(newParagraph, 0)
|
||||||
@ -377,8 +386,9 @@ export class MyBiz {
|
|||||||
let curS = window.myEdit.utils.GetSelection();
|
let curS = window.myEdit.utils.GetSelection();
|
||||||
let curP = window.myEdit.utils.GetEventTarget(event);
|
let curP = window.myEdit.utils.GetEventTarget(event);
|
||||||
let styleName = curP.getAttribute("data-value");
|
let styleName = curP.getAttribute("data-value");
|
||||||
if (styleName === undefined) {
|
if (styleName === undefined || styleName === null) {
|
||||||
styleName = curP.parentNode.getAttribute("data-value");
|
styleName = curP.closest("span").getAttribute("data-value");
|
||||||
|
console.log("closest: ", curP, curP.closest("span"))
|
||||||
}
|
}
|
||||||
let className = this.parseStyleName2ClassName(styleName)
|
let className = this.parseStyleName2ClassName(styleName)
|
||||||
//todo 只对 nodeType = p 执行
|
//todo 只对 nodeType = p 执行
|
||||||
|
@ -6,6 +6,11 @@
|
|||||||
export class MyEventListener {
|
export class MyEventListener {
|
||||||
|
|
||||||
constructor(styleClass) {
|
constructor(styleClass) {
|
||||||
|
//这里监听鼠标按下事件
|
||||||
|
document.getElementById("_style_utils").addEventListener("mousedown", function (e) {
|
||||||
|
const event = window.myEdit.utils.ParseEvent(e);
|
||||||
|
window.myEdit.utils.ProhibitDefaultEvent(event);
|
||||||
|
},true)
|
||||||
|
|
||||||
//样式事件
|
//样式事件
|
||||||
let styleList = document.getElementsByClassName(styleClass);
|
let styleList = document.getElementsByClassName(styleClass);
|
||||||
@ -93,6 +98,7 @@ export class MyEventListener {
|
|||||||
*/
|
*/
|
||||||
InputListener(e) {
|
InputListener(e) {
|
||||||
const event = window.myEdit.utils.ParseEvent(e);
|
const event = window.myEdit.utils.ParseEvent(e);
|
||||||
|
console.log("input : ",event)
|
||||||
window.myEdit.biz.inputHandle(event);
|
window.myEdit.biz.inputHandle(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +119,7 @@ export class MyEventListener {
|
|||||||
*/
|
*/
|
||||||
CompositionendListener(e) {
|
CompositionendListener(e) {
|
||||||
const event = window.myEdit.utils.ParseEvent(e);
|
const event = window.myEdit.utils.ParseEvent(e);
|
||||||
|
console.log("Compositionend : ",event)
|
||||||
window.myEdit.biz.compositionendHandle(event);
|
window.myEdit.biz.compositionendHandle(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,12 +139,6 @@ export class MyEventListener {
|
|||||||
*/
|
*/
|
||||||
MouseUp(e) {
|
MouseUp(e) {
|
||||||
let styleUtils = document.getElementById("_style_utils");
|
let styleUtils = document.getElementById("_style_utils");
|
||||||
|
|
||||||
styleUtils.addEventListener("mousedown", function (e) {
|
|
||||||
const event = window.myEdit.utils.ParseEvent(e);
|
|
||||||
window.myEdit.utils.ProhibitDefaultEvent(event);
|
|
||||||
})
|
|
||||||
|
|
||||||
if (window.myEdit.utils.GetSelection().isCollapsed) {
|
if (window.myEdit.utils.GetSelection().isCollapsed) {
|
||||||
styleUtils.style.display = "none";
|
styleUtils.style.display = "none";
|
||||||
return
|
return
|
||||||
|
2
static/js/lib/todolist
Normal file
2
static/js/lib/todolist
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
选择文字 第一次添加样式的时候 丢失选区问题
|
||||||
|
|
@ -10,7 +10,7 @@
|
|||||||
<link rel="stylesheet" type="text/css" href="./css/myEdit.css">
|
<link rel="stylesheet" type="text/css" href="./css/myEdit.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body style="display: flex; flex-direction:column; ">
|
<body style="display: flex; flex-direction:column; background-color: #ffebc3">
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
<div class="fixStylePosition" id="_style_utils">
|
<div class="fixStylePosition" id="_style_utils">
|
||||||
@ -59,15 +59,15 @@
|
|||||||
<div class="my-divider-item"></div>
|
<div class="my-divider-item"></div>
|
||||||
<div style="display: flex;">
|
<div style="display: flex;">
|
||||||
<span class="fixStyleInnerSpan" data-value="b">
|
<span class="fixStyleInnerSpan" data-value="b">
|
||||||
<svg data-value="b" width="1.8rem" height="1.8rem" viewBox="0 0 24 24"
|
<svg width="1.8rem" height="1.8rem" viewBox="0 0 24 24"
|
||||||
fill="none"
|
fill="none"
|
||||||
xmlns="http://www.w3.org/2000/svg" data-icon="BoldOutlined">
|
xmlns="http://www.w3.org/2000/svg" data-icon="BoldOutlined">
|
||||||
<path data-value="b" d="M5 2.709C5 2.317 5.317 2 5.709 2h6.734a5.317 5.317 0 0 1 3.686 9.148 5.671 5.671 0 0 1-2.623 10.7H5.71a.709.709 0 0 1-.71-.707V2.71Zm2 7.798h5.443a3.19 3.19 0 0 0 3.19-3.19c0-1.762-1.428-3.317-3.19-3.317H7v6.507Zm0 2.126v7.09h6.507a3.544 3.544 0 0 0 0-7.09H7Z"
|
<path d="M5 2.709C5 2.317 5.317 2 5.709 2h6.734a5.317 5.317 0 0 1 3.686 9.148 5.671 5.671 0 0 1-2.623 10.7H5.71a.709.709 0 0 1-.71-.707V2.71Zm2 7.798h5.443a3.19 3.19 0 0 0 3.19-3.19c0-1.762-1.428-3.317-3.19-3.317H7v6.507Zm0 2.126v7.09h6.507a3.544 3.544 0 0 0 0-7.09H7Z"
|
||||||
fill="currentColor"></path>
|
fill="currentColor"></path>
|
||||||
</svg>
|
</svg>
|
||||||
</span>
|
</span>
|
||||||
<span class="fixStyleInnerSpan" data-value="del">
|
<span class="fixStyleInnerSpan" data-value="del">
|
||||||
<svg data-value="del" width="1.8rem" height="1.8rem"
|
<svg width="1.8rem" height="1.8rem"
|
||||||
viewBox="0 0 24 24" fill="none"
|
viewBox="0 0 24 24" fill="none"
|
||||||
xmlns="http://www.w3.org/2000/svg" data-icon="HorizontalLineOutlined">
|
xmlns="http://www.w3.org/2000/svg" data-icon="HorizontalLineOutlined">
|
||||||
<path
|
<path
|
||||||
@ -76,7 +76,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</span>
|
</span>
|
||||||
<span class="fixStyleInnerSpan" data-value="i">
|
<span class="fixStyleInnerSpan" data-value="i">
|
||||||
<svg data-value="i" width="1.8rem" height="1.8rem" viewBox="0 0 24 24"
|
<svg width="1.8rem" height="1.8rem" viewBox="0 0 24 24"
|
||||||
fill="none"
|
fill="none"
|
||||||
xmlns="http://www.w3.org/2000/svg" data-icon="ItalicOutlined">
|
xmlns="http://www.w3.org/2000/svg" data-icon="ItalicOutlined">
|
||||||
<path
|
<path
|
||||||
@ -85,7 +85,7 @@
|
|||||||
</svg>
|
</svg>
|
||||||
</span>
|
</span>
|
||||||
<span class="fixStyleInnerSpan" data-value="u">
|
<span class="fixStyleInnerSpan" data-value="u">
|
||||||
<svg data-value="u" width="1.8rem" height="1.8rem" viewBox="0 0 24 24"
|
<svg width="1.8rem" height="1.8rem" viewBox="0 0 24 24"
|
||||||
fill="none"
|
fill="none"
|
||||||
xmlns="http://www.w3.org/2000/svg" data-icon="UnderlineOutlined">
|
xmlns="http://www.w3.org/2000/svg" data-icon="UnderlineOutlined">
|
||||||
<path
|
<path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user