PiranhaCMS / piranha.core

Piranha CMS is the friendly editor-focused CMS for .NET that can be used both as an integrated CMS or as a headless API.
http://piranhacms.org
MIT License
1.99k stars 555 forks source link

Stable Block UID for autosaving of inline content #1372

Open mikaellindemann opened 4 years ago

mikaellindemann commented 4 years ago

I would like to provide an in-browser autosave feature in a custom editor in the Piranha manager interface.

I need a unique ID that is the same over multiple reloads of the manager interface, such that the content can be stored in local storage.

Currently, it seems that the UID of a block changes on every load, rendering the stored items in local storage unusable when stored using the UID.

Is it possible to get another identifier of the block that is stable over time, or is my best option to use some calculated unique identifier, e.g. the page GUID + index of the block item?

tidyui commented 4 years ago

Hi there! Yes the current UID is only provided in the manager models to have a unique instance for binding the Vue.js frontend, and like you say it's randomized. The problem here is that neither fields, or regions have a unique id that is communicated through the models, however instead of being calculated like:

"uid-" + Math.Abs(Guid.NewGuid().GetHashCode()).ToString();

it could instead be calculated like:

"uid-" + Math.Abs((RegionName + FieldName).GetHashCode()).ToString();
mikaellindemann commented 4 years ago

How could it be solved for blocks? It seems a bit different as we don't have a unique name for it, and the order of elements could change or I could add another block of the same type before my current instance.

tidyui commented 3 years ago

When editor models and views are consolidated in #1224 we should implement this.

tidyui commented 3 years ago

Looking at this for 10.0. Region UID will be calculated from property name which will be persistent. Block UID will be calculated from block Id which should be persistent between saves.

tidyui commented 2 years ago

This will be done together with #1224 for v11.0