diff --git a/wax-prosemirror-services/src/ImageService/fileUpload.js b/wax-prosemirror-services/src/ImageService/fileUpload.js index 1798e96da2b89191953e9f36fdfded7cfd7ca113..de699b77a9b795bb671faa723a61f4ab18f8dfcb 100644 --- a/wax-prosemirror-services/src/ImageService/fileUpload.js +++ b/wax-prosemirror-services/src/ImageService/fileUpload.js @@ -6,7 +6,7 @@ const findPlaceholder = (state, id, placeholderPlugin) => { return found.length ? found[0].from : null; }; -export default (view, fileUpload, placeholderPlugin) => (file, customAttrs) => { +export default (view, fileUpload, placeholderPlugin) => file => { const { state } = view; // A fresh object to act as the ID for this upload const id = {}; @@ -20,8 +20,9 @@ export default (view, fileUpload, placeholderPlugin) => (file, customAttrs) => { }); view.dispatch(tr); + fileUpload(file).then( - url => { + (url, extraData = {}) => { const pos = findPlaceholder(view.state, id, placeholderPlugin); // If the content around the placeholder has been deleted, drop // the image @@ -38,7 +39,7 @@ export default (view, fileUpload, placeholderPlugin) => (file, customAttrs) => { view.state.schema.nodes.image.create({ src: url, id: uuidv4(), - customAttrs, + extraData, }), ) .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 523f349181507ef6e8184ec2f3bba6db5ac634c6..2dba4d90dce02cbe39d4fde2bef69254aaa6c8a1 100644 --- a/wax-prosemirror-services/src/ImageService/schema/imageNode.js +++ b/wax-prosemirror-services/src/ImageService/schema/imageNode.js @@ -1,12 +1,13 @@ // import { SchemaHelpers } from 'wax-prosemirror-core'; import { isEmpty } from 'lodash'; + const imageNode = { attrs: { id: { default: '' }, src: {}, alt: { default: '' }, title: { default: null }, - customAttrs: { default: {} }, + extraData: { default: {} }, // track: { default: [] }, fileid: { default: null }, }, @@ -38,6 +39,7 @@ const imageNode = { const { src, alt, title, id, track, fileid } = hook.node.attrs; // eslint-disable-next-line no-param-reassign + const { extraData } = hook.node.attrs; hook.value = [ 'img', { @@ -47,18 +49,14 @@ const imageNode = { 'data-id': id, // 'data-track': track, 'data-fileid': fileid, + ...Object.keys(extraData).reduce((obj, key) => { + // eslint-disable-next-line no-param-reassign + obj[`data-${key}`] = extraData[key]; + return obj; + }, {}), }, ]; - 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(); }, };