voidlabs / mosaico

Mosaico - Responsive Email Template Editor
https://mosaico.io
GNU General Public License v3.0
1.7k stars 500 forks source link

Where are block IDs generated #521

Closed louis71barker closed 5 years ago

louis71barker commented 5 years ago

Hi, does anyone know which file is used to generate the block ids when a block is dragged in? im trying to pickypack this process with some custom guid for our editor and for the life of me i can not figure out where the IDs are generated when the block is dragged in? or any function that is called when a block is dragged in. Any help would be super appreciated

bago commented 5 years ago

This is the answer for 0.17.5 and previous releases (current head and future releases may change this).

You have to understand KnockoutJS first.

Block IDs are generated mainly by the "uniqueid" knockout binding: https://github.com/voidlabs/mosaico/blob/v0.17.5/src/js/bindings/virtuals.js#L7

The "uniqueid" binding is added by the parser while parsing the master template and generating block templates: https://github.com/voidlabs/mosaico/blob/v0.17.5/src/js/converter/parser.js#L35

Sometimes (when a bunch of blocks are inserted at bulk via custom methods or via undo/redo of bulk blocks operations, but they shouldn't happen in "normal" 0.17.x use cases) they are generated elsewhere: https://github.com/voidlabs/mosaico/blob/v0.17.5/src/js/viewmodel.js#L166 https://github.com/voidlabs/mosaico/blob/v0.17.5/src/js/converter/wrapper.js#L274