These are chat archives for GetmeUK/ContentTools

11th
Sep 2016
Anthony Blackshaw
@anthonyjb
Sep 11 2016 21:11

@oodavid hi - CT has a brute force approach to history where we simply check each editable region frequently (every 250ms I think) for modified content using the last modified date/time attribute and then record any changes in a history stack. The major pro being typically it supports new features and tools added to the editor without any work because we're just taking snapshots.

At the moment the history stack doesn't take account of editable regions because in the base editor these aren't dynamic but this is where you'd need to start (and I don't think it would be too difficult): https://github.com/GetmeUK/ContentTools/blob/master/src/scripts/history.coffee

You'd need to modify the history snapshot the current map of regions, checking for new regions whenever the content changed (in the same way it does now), the tricker bit to this is that currently history replaces the content of the region in question on an undo with the previous snapshot, where as in your case it would also need to remove or re-add a regions dynamically into the HTML and then sync the regions with the editor - but again I think that's possible and I'd be happy to help you as much as I can.

I do apologise for the late reply I was away Friday/Saturday and had limited access to wifi

David King
@oodavid
Sep 11 2016 21:42
@anthonyjb oh hey no worries! I've been reading through the sources and realised that was the case. I've come to the conclusion that I want to bypass the ContentTools history and roll my own (for now) - the reason is simple. My CMS acts on an <article> element and has the ability to add <section> elements, these may contain pre-built snippets (latest blog article, last 5 tweets etc.) or contain ContentEditable regions.
Because the sections and snippets vary with regards to settings, modifiable styles etc. I reckon a quick win would be to copy the ContentTools history logic to act on my entire <article> element. This way I'll be capturing settings and style changes too.
I'll see if I can change the History API interface (in a non-breaking way) to work on elements other than ContentTools regions, maybe something like stack.watch('#myArticle') or somesuch. My instinct is that this is a dead-end, but maybe worth a try.
Either way, I've come to the same conclusion that the "brute force logic" is the best way to go, but in my instance it's a single element further up the DOM.
I'll keep you posted, this is very much a project for skilling up!