In my editor, images can be referred.
I define image
node with an extra id
attr, and ref
node which just keeps the id
of the referred image.
I also have a global imgs = {}
, which stores id: image-dom-node
. It works for two purpose:
- guarantee a unique
id
be generated for new image is inserted - when a
ref
is hovered on, the referred image can be previewed instantly
However, it brings the sync problems
- images could be deleted, leaves the dom node invalid
- cut images and paste back also makes the dom node in
imgs
invalid - other images and refs may be copied from another editor, new items (duplicated
id
being replaced with a uniqueid
) should be inserted intoimgs
How should I deal with each problem above?