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

image customAttrs

parent e786663e
No related branches found
No related tags found
1 merge request!426Questions ToolGroup
...@@ -170,7 +170,7 @@ const Hhmi = () => { ...@@ -170,7 +170,7 @@ const Hhmi = () => {
value={content} value={content}
readonly={readOnly} readonly={readOnly}
layout={HhmiLayout} layout={HhmiLayout}
// onChange={source => console.log(source)} onChange={source => console.log(source)}
/> />
</> </>
); );
......
...@@ -6,9 +6,8 @@ const findPlaceholder = (state, id, placeholderPlugin) => { ...@@ -6,9 +6,8 @@ const findPlaceholder = (state, id, placeholderPlugin) => {
return found.length ? found[0].from : null; return found.length ? found[0].from : null;
}; };
export default (view, fileUpload, placeholderPlugin) => file => { export default (view, fileUpload, placeholderPlugin) => (file, customAttrs) => {
const { state } = view; const { state } = view;
// A fresh object to act as the ID for this upload // A fresh object to act as the ID for this upload
const id = {}; const id = {};
...@@ -36,12 +35,10 @@ export default (view, fileUpload, placeholderPlugin) => file => { ...@@ -36,12 +35,10 @@ export default (view, fileUpload, placeholderPlugin) => file => {
.replaceWith( .replaceWith(
pos, pos,
pos, pos,
// view.state.schema.nodes.image.create({
// src: url,
// }),
view.state.schema.nodes.image.create({ view.state.schema.nodes.image.create({
src: url, src: url,
id: uuidv4(), id: uuidv4(),
customAttrs,
}), }),
) )
.setMeta(placeholderPlugin, { remove: { id } }), .setMeta(placeholderPlugin, { remove: { id } }),
......
// import { SchemaHelpers } from 'wax-prosemirror-core'; // import { SchemaHelpers } from 'wax-prosemirror-core';
import { isEmpty } from 'lodash';
const imageNode = { const imageNode = {
attrs: { attrs: {
id: { default: '' }, id: { default: '' },
src: {}, src: {},
alt: { default: '' }, alt: { default: '' },
title: { default: null }, title: { default: null },
customAttrs: { default: {} },
// track: { default: [] }, // track: { default: [] },
fileid: { default: null }, fileid: { default: null },
}, },
...@@ -29,7 +30,6 @@ const imageNode = { ...@@ -29,7 +30,6 @@ const imageNode = {
], ],
toDOM(hook, next) { toDOM(hook, next) {
const attrs = {}; const attrs = {};
if (hook.node.attrs.track && hook.node.attrs.track.length) { if (hook.node.attrs.track && hook.node.attrs.track.length) {
// attrs['data-track'] = JSON.stringify(hook.node.attrs.track); // attrs['data-track'] = JSON.stringify(hook.node.attrs.track);
attrs['data-id'] = hook.node.attrs.id; attrs['data-id'] = hook.node.attrs.id;
...@@ -49,6 +49,16 @@ const imageNode = { ...@@ -49,6 +49,16 @@ const imageNode = {
'data-fileid': fileid, 'data-fileid': fileid,
}, },
]; ];
if (
hook.node.attrs.customAttrs.customAttrs &&
!isEmpty(hook.node.attrs.customAttrs.customAttrs)
) {
const { customAttrs } = hook.node.attrs.customAttrs;
Object.assign(hook.value[1], { ...customAttrs });
}
next(); next();
}, },
}; };
......
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