diff --git a/editors/demo/src/HHMI/HHMI.js b/editors/demo/src/HHMI/HHMI.js index 2b562b31325db1591767e853b2675f6131a2025d..a232017d224a2e7f00137867d29435d4ec89bb56 100644 --- a/editors/demo/src/HHMI/HHMI.js +++ b/editors/demo/src/HHMI/HHMI.js @@ -170,7 +170,7 @@ const Hhmi = () => { value={content} readonly={readOnly} layout={HhmiLayout} - // onChange={source => console.log(source)} + onChange={source => console.log(source)} /> </> ); diff --git a/wax-prosemirror-services/src/ImageService/fileUpload.js b/wax-prosemirror-services/src/ImageService/fileUpload.js index 7dc77815556a1d370e7c54fb377ceb4320be9b4b..1798e96da2b89191953e9f36fdfded7cfd7ca113 100644 --- a/wax-prosemirror-services/src/ImageService/fileUpload.js +++ b/wax-prosemirror-services/src/ImageService/fileUpload.js @@ -6,9 +6,8 @@ const findPlaceholder = (state, id, placeholderPlugin) => { return found.length ? found[0].from : null; }; -export default (view, fileUpload, placeholderPlugin) => file => { +export default (view, fileUpload, placeholderPlugin) => (file, customAttrs) => { const { state } = view; - // A fresh object to act as the ID for this upload const id = {}; @@ -36,12 +35,10 @@ export default (view, fileUpload, placeholderPlugin) => file => { .replaceWith( pos, pos, - // view.state.schema.nodes.image.create({ - // src: url, - // }), view.state.schema.nodes.image.create({ src: url, id: uuidv4(), + customAttrs, }), ) .setMeta(placeholderPlugin, { remove: { id } }), diff --git a/wax-prosemirror-services/src/ImageService/schema/imageNode.js b/wax-prosemirror-services/src/ImageService/schema/imageNode.js index 69a3b05be18b6b2191befb93ee518398f9c9ad19..523f349181507ef6e8184ec2f3bba6db5ac634c6 100644 --- a/wax-prosemirror-services/src/ImageService/schema/imageNode.js +++ b/wax-prosemirror-services/src/ImageService/schema/imageNode.js @@ -1,11 +1,12 @@ // import { SchemaHelpers } from 'wax-prosemirror-core'; - +import { isEmpty } from 'lodash'; const imageNode = { attrs: { id: { default: '' }, src: {}, alt: { default: '' }, title: { default: null }, + customAttrs: { default: {} }, // track: { default: [] }, fileid: { default: null }, }, @@ -29,7 +30,6 @@ const imageNode = { ], toDOM(hook, next) { const attrs = {}; - if (hook.node.attrs.track && hook.node.attrs.track.length) { // attrs['data-track'] = JSON.stringify(hook.node.attrs.track); attrs['data-id'] = hook.node.attrs.id; @@ -49,6 +49,16 @@ const imageNode = { '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(); }, };