From d83d6d84aed37aeeb458aeb2ee76b34f37c70f1d Mon Sep 17 00:00:00 2001 From: chris <kokosias@yahoo.gr> Date: Tue, 15 Nov 2022 14:27:03 +0200 Subject: [PATCH] image customAttrs --- editors/demo/src/HHMI/HHMI.js | 2 +- .../src/ImageService/fileUpload.js | 7 ++----- .../src/ImageService/schema/imageNode.js | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/editors/demo/src/HHMI/HHMI.js b/editors/demo/src/HHMI/HHMI.js index 2b562b313..a232017d2 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 7dc778155..1798e96da 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 69a3b05be..523f34918 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(); }, }; -- GitLab