306 lines
11 KiB
JavaScript
306 lines
11 KiB
JavaScript
// nodes.js — node elements and their content.
|
|
//
|
|
// Content HTML is cached by *content*, not by node id. That is what makes undo
|
|
// free: undoing a text edit restores the previous string, whose rendered HTML
|
|
// is already in the cache, so no request is made. Keying by node id would turn
|
|
// every Ctrl+Z into a render round trip.
|
|
//
|
|
// The server pre-renders every text and file node and ships the result with the
|
|
// page, so a canvas opens with the cache already warm and issues no content
|
|
// requests at all until something is edited.
|
|
window.Canvas = window.Canvas || {};
|
|
|
|
Canvas.Nodes = (function () {
|
|
var Doc = Canvas.Doc;
|
|
var Select = Canvas.Select;
|
|
|
|
var nodeLayer = null;
|
|
var groupLayer = null;
|
|
var els = {}; // node id -> element
|
|
var cache = {}; // content key -> rendered HTML
|
|
var inflight = {}; // content key -> Promise
|
|
|
|
var SIDES = ['top', 'right', 'bottom', 'left'];
|
|
var CORNERS = ['nw', 'ne', 'se', 'sw'];
|
|
|
|
// SEP separates the fields of a content key. A NUL can never appear in a
|
|
// path or in markdown, so no two different nodes can collide on one key.
|
|
var SEP = ' |