Changing doc attribute in collab

Hi,

I am working on a simple collaborative editor. I am trying to implement a functionality to show/hide all images in the editor based on document attribute flag. For this, added a document attribute and from a custom menu command did the following:

const transaction = state.tr.step(new SetDocAttr(‘custAttrFlag’, ‘myVal’)) dispatch(transaction)

Followed this (Changing doc.attrs?) and the document attribute is getting update locally, but not collaborative.

Is there is any limitation in this case with prose-mirror?

Please help and suggest how can I achieve this. Appreciate quick response. Thanks for considering!

I don’t see a reason that wouldn’t work. Have you checked whether the step is being propagated normally and is arriving at other clients?

Thanks for the quick reply!

All other default Steps (ReplaceStep, ReplaceAroundStep, AddMarkStep, RemoveMarkStep) works fine. I am doing this from a plugin. May be that the collab module is unaware of our custom Step(SetDocAttr), though have registered using Step.jsonID(“SetDocAttr”, SetDocAttrStep)?

No, that doesn’t sound likely. You’ll have to debug your code to find out what’s going wrong.

Step.fromJSON = function fromJSON (schema, json) { if (!json || !json.stepType) { throw new RangeError(“Invalid input for Step.fromJSON”) } var type = stepsByID[json.stepType];

When debugging the collab server module it revealed that stepsByID doesn’t have our " SetDocAttrStep". This custom step is initialised from our plugin and thus is not registered with the collab server (and registered on the client side application alone) and thus throws range error “No step type SetDocAttr defined”. Are we doing anything wrong here?

Collaboration server & Editor application (web) server (different instances) are running at different locations.

You will have to be able do deserialize the steps on the server too, unless it just passes through the JSON without ever converting it into Step instances. But not having that would result in an error, not silently not working, so that doesn’t sound like it’s the problem.