Page builder

A page builder like Webflow’s, Wix’s or Elementor’s:
examples/dnd/page_builder.py.
python examples/dnd/page_builder.py-
Blocks hold blocks. A page is a list of blocks; a “Two columns” block has two lists of its own:
def block(kind):b = {"id": f"block-{next(_ids)}", "kind": kind}if kind == "columns":b["left"], b["right"] = [], []return b -
Every list has an id. The page is
"page"and each column is"<block id>:left"or":right". A function finds them all, so one handler serves every list:def lists(self):found = {"page": self.page}for b in self.page:if b["kind"] == "columns":found[b["id"] + ":left"], found[b["id"] + ":right"] = b["left"], b["right"]return founddef drop(self, event):if event.from_list == "library":self.lists()[event.target].insert(event.index, block(event.data))else:pz.dnd.move(self.lists(), event) -
Sortables inside sortables. A columns block draws two sortables, with the same group as the page. The deepest list under the pointer takes the drop; a block being dragged never takes itself.
pz.sortable(items=b[side], item=self.render, id=f"{b['id']}:{side}", group="blocks",handle=True, padding=8, width="fill", on_reorder=self.drop,can_drop=lambda e: not is_columns(e.data)) # no columns in columns -
The library is a grid that copies.
direction="wrap"lays it out in rows,pull="clone"andsort=Falsemake it a palette. -
Phone width. A segmented control changes the page width, and the columns stack. The sortables animate to their new places.