mirror of https://github.com/fantasticit/think.git
tiptap: only use dynamic placeholder in edit
This commit is contained in:
parent
cb811ab21f
commit
2f97380e63
|
@ -56,6 +56,9 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
||||||
|
|
||||||
const start = pos;
|
const start = pos;
|
||||||
const end = pos + node.nodeSize;
|
const end = pos + node.nodeSize;
|
||||||
|
let placeholder = '';
|
||||||
|
|
||||||
|
if (this.editor.isEditable) {
|
||||||
const key = `${start}-${end}`;
|
const key = `${start}-${end}`;
|
||||||
|
|
||||||
if (!this.editor.storage[this.name].has(key)) {
|
if (!this.editor.storage[this.name].has(key)) {
|
||||||
|
@ -70,15 +73,26 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
||||||
: this.options.placeholder
|
: this.options.placeholder
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
placeholder = this.editor.storage[this.name].get(key);
|
||||||
const decoration = Decoration.node(start, end, {
|
|
||||||
'class': classes.join(' '),
|
|
||||||
'data-placeholder': this.editor.storage[this.name].get(key),
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.editor.storage[this.name].delete(key);
|
this.editor.storage[this.name].delete(key);
|
||||||
}, 500);
|
}, 500);
|
||||||
|
} else {
|
||||||
|
placeholder =
|
||||||
|
typeof this.options.placeholder === 'function'
|
||||||
|
? this.options.placeholder({
|
||||||
|
editor: this.editor,
|
||||||
|
node,
|
||||||
|
pos,
|
||||||
|
})
|
||||||
|
: this.options.placeholder;
|
||||||
|
}
|
||||||
|
|
||||||
|
const decoration = Decoration.node(start, end, {
|
||||||
|
'class': classes.join(' '),
|
||||||
|
'data-placeholder': placeholder,
|
||||||
|
});
|
||||||
|
|
||||||
decorations.push(decoration);
|
decorations.push(decoration);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue