Skip to content

Commit

Permalink
refactor: set certain default values for the method of inserting content
Browse files Browse the repository at this point in the history
  • Loading branch information
imzbf committed Dec 28, 2023
1 parent be86821 commit 392dcc8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,9 @@ editorRef.value?.triggerSave();
editorRef.value?.insert((selectedText) => {
/**
* @return targetValue 待插入内容
* @return select 插入后是否自动选中内容
* @return deviationStart 插入后选中内容鼠标开始位置
* @return deviationEnd 插入后选中内容鼠标结束位置
* @return select 插入后是否自动选中内容,默认:true
* @return deviationStart 插入后选中内容鼠标开始位置,默认:0
* @return deviationEnd 插入后选中内容鼠标结束位置,默认:0
*/
return {
targetValue: `${selectedText}`,
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,9 @@ Manually insert content into textarea.
editorRef.value?.insert((selectedText) => {
/**
* @return targetValue Content to be inserted
* @return select Automatically select content
* @return deviationStart Start position of the selected content
* @return deviationEnd End position of the selected content
* @return select Automatically select content, default: true
* @return deviationStart Start position of the selected content, default: 0
* @return deviationEnd End position of the selected content, default: 0
*/
return {
targetValue: `${selectedText}`,
Expand Down
21 changes: 18 additions & 3 deletions dev/Preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,24 @@ export default defineComponent({
// autoDetectCode
// onHtmlChanged={console.log}
// onError={console.log}
onDrop={async (e) => {
e.stopPropagation();

const form = new FormData();
form.append('file', e.dataTransfer?.files[0] as any);

const res = await axios.post('/api/img/upload', form, {
headers: {
'Content-Type': 'multipart/form-data'
}
});

editorRef.value?.insert(() => {
return {
targetValue: `![](${res.data.url})`
};
});
}}
onSave={(v, h) => {
console.log('onSave');
h.then((html) => {
Expand Down Expand Up @@ -383,9 +401,6 @@ export default defineComponent({
'catalog',
'github'
]}
// onDrop={(e) => {
// console.log('ee', e);
// }}
defToolbars={
<>
<Normal />
Expand Down
6 changes: 3 additions & 3 deletions packages/MdEditor/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,11 @@ export interface InsertParam {
// 插入的内容
targetValue: string;
// 是否选中插入的内容
select: boolean;
select?: boolean;
// 选中位置的开始偏移量
deviationStart: number;
deviationStart?: number;
// 选中位置的结束偏移量
deviationEnd: number;
deviationEnd?: number;
}
/**
* 插入的内容的构造函数
Expand Down
6 changes: 3 additions & 3 deletions packages/MdEditor/utils/content-help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ export const directive2flag = (
const insertOptions = generate(selectedText);

targetValue = insertOptions.targetValue;
select = insertOptions.select;
deviationStart = insertOptions.deviationStart;
deviationEnd = insertOptions.deviationEnd;
select = insertOptions.select || true;
deviationStart = insertOptions.deviationStart || 0;
deviationEnd = insertOptions.deviationEnd || 0;
}
}
}
Expand Down

0 comments on commit 392dcc8

Please sign in to comment.