fix: backcolor & paste ul

This commit is contained in:
yanmao 2022-01-06 01:32:12 +08:00
parent c9caf05e60
commit 3df7f31b14
3 changed files with 48 additions and 7 deletions

View File

@ -178,9 +178,26 @@ export default class Paste {
}
return false;
};
rootChildren.forEach((child) => {
/**
* <ul><ul></ul><li></li></ul>
* <ul><li></li><ul></ul><li></li></ul>
* <ul><li></li><ul></ul></ul>
*/
rootChildren.forEach((child, index) => {
if (!child) return;
if (child.equal(node)) {
// 最后一个位置加入到右边
if (rootChildren.length - 1 === index) {
appendToTemp();
rightList.push(node);
}
// 在第一个位置,加入到最左边
else if (index === 0) leftList.push(node);
// 中间位置先append然后加入到左边
else {
appendToTemp();
leftList.push(node);
}
isLeft = false;
return;
}
@ -195,8 +212,8 @@ export default class Paste {
});
appendToTemp();
const indent = parent.attributes('data-indent') || '0';
this.engine.list.addIndent(node, parseInt(indent, 10));
leftList.push(node);
node.attributes('data-indent', indent);
this.engine.list.addIndent(node, 1);
let prev = parent;
leftList.forEach((childNode) => {
const child = $(childNode);
@ -211,7 +228,7 @@ export default class Paste {
prev = child;
});
parent.remove();
return node.next() || undefined;
return node || undefined;
}
// 补齐 li
if (node.name !== 'li' && parentIsList) {
@ -269,7 +286,8 @@ export default class Paste {
if (isList) {
const indent =
$(leftLast)?.attributes('data-indent') || '0';
this.engine.list.addIndent(node, parseInt(indent, 10));
node.attributes('data-indent', indent);
this.engine.list.addIndent(node, 1);
leftList[leftList.length] = node[0];
li = null;
return;

View File

@ -29,6 +29,8 @@
"vue": "^3.2.9"
},
"devDependencies": {
"@vue/compiler-sfc": "^3.2.9"
"@vue/compiler-sfc": "^3.2.9",
"@types/keymaster": "^1.6.28",
"@types/lodash": "^4.14.178"
}
}

View File

@ -1,4 +1,4 @@
import { MarkPlugin, PluginOptions } from '@aomao/engine';
import { $, ConversionData, MarkPlugin, PluginOptions } from '@aomao/engine';
export interface BackcolorOptions extends PluginOptions {
hotkey?: { key: string; args: Array<string> };
@ -21,6 +21,27 @@ export default class<T extends BackcolorOptions> extends MarkPlugin<T> {
},
};
conversion(): ConversionData {
return [
{
from: (name, styles) => {
return name === this.tagName && !!styles.background;
},
to: (name, styles, attributes) => {
const toNode = $(`<${name} />`);
const background = styles['background'];
delete styles['background'];
styles['background-color'] = background;
toNode.css(styles);
Object.keys(attributes).forEach((name) => {
toNode.attributes(name, attributes[name]);
});
return toNode;
},
},
];
}
isTrigger(color: string, defaultColor?: string) {
return defaultColor === undefined || color !== defaultColor;
}