Skip to content
Snippets Groups Projects
Commit 85c45cb8 authored by chris's avatar chris
Browse files

caption in progress

parent 4d3512c9
No related branches found
No related tags found
1 merge request!259Captions
import { DecorationSet } from 'prosemirror-view';
import { Plugin, PluginKey } from 'prosemirror-state';
import { Plugin, PluginKey, NodeSelection } from 'prosemirror-state';
const captionPlugin = key =>
new Plugin({
......@@ -29,23 +29,23 @@ const captionPlugin = key =>
e.target.nodeName === 'IMG' &&
e.target.parentNode.lastElementChild.nodeName !== 'FIGCAPTION'
) {
let pos = view.posAtDOM(e.target);
const id = {};
const { tr } = view.state;
const pos = view.posAtDOM(e.target);
const pos1 = pos + 1;
pos += 1;
// insert figure caption node
view.dispatch(
tr
.replaceWith(
pos1,
pos1,
pos,
pos,
view.state.schema.nodes.figcaption.create({
class: 'decoration',
dataContent: 'Caption : ',
}),
)
.setMeta(captionPlugins, {
add: { id, pos: pos + 1 },
add: { id, pos },
}),
);
} else if (e.target.nodeName !== 'FIGCAPTION') {
......@@ -68,6 +68,19 @@ const captionPlugin = key =>
}
}
if (e.target.nodeName === 'IMG') {
let pos = view.posAtDOM(e.target);
const { $from } = view.state.selection;
const same = $from.sharedDepth(pos);
if (same === 0) return false;
pos = $from.before(same);
view.dispatch(
view.state.tr.setSelection(
NodeSelection.create(view.state.doc, pos),
),
);
}
return true;
},
keyup(view, e) {
......
......@@ -8,7 +8,7 @@ const image = {
track: { default: [] },
},
group: 'figure',
draggable: true,
draggable: false,
parseDOM: [
{
tag: 'img[src]',
......
......@@ -27,7 +27,12 @@ class Heading2 extends Tools {
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.name === 'list_item' || node.type.name === 'image') {
if (
node.type.name === 'list_item' ||
node.type.name === 'image' ||
node.type.name === 'figure' ||
node.type.name === 'figcaption'
) {
isActive = false;
}
});
......
......@@ -27,7 +27,12 @@ class Heading3 extends Tools {
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.name === 'list_item' || node.type.name === 'image') {
if (
node.type.name === 'list_item' ||
node.type.name === 'image' ||
node.type.name === 'figure' ||
node.type.name === 'figcaption'
) {
isActive = false;
}
});
......
......@@ -27,7 +27,12 @@ class Heading4 extends Tools {
if (activeViewId !== 'main') return false;
const { from, to } = state.selection;
state.doc.nodesBetween(from, to, (node, pos) => {
if (node.type.name === 'list_item' || node.type.name === 'image') {
if (
node.type.name === 'list_item' ||
node.type.name === 'image' ||
node.type.name === 'figure' ||
node.type.name === 'figcaption'
) {
isActive = false;
}
});
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment