import { createElement } from "../../lib/skeleton/index.js"; import { CSS } from "../../helpers/loader.js"; const $tmpl = createElement(`
directory Videos 06/06/2020
`); export const css = CSS(import.meta.url, "thing.css"); // a filesystem "thing" is typically either a file or folder which have a lot of behavior builtin. // Probably one day we can rename that to something more clear but the gist is a thing can be // displayed in list mode / grid mode, have some substate to enable loading state for upload, // can toggle links, potentially includes a thumbnail, can be used as a source and target for // drag and drop on other folders and many other non obvious stuff export function createThing({ name = null, // type = "N/A", // size = 0, // time = null, link = "", // permissions = {} }) { const $thing = $get(); if ($thing instanceof HTMLElement) { const $label = $thing.querySelector(".component_filename .file-details > span"); if ($label instanceof HTMLElement) $label.textContent = name; $thing?.querySelector("a")?.setAttribute("href", link); } return $thing; } function $get() { // the very first implementation was: return $tmpl.cloneNode(true); // the major issue was cloneNode is slow and would often make us miss an animationFrame. A much more // efficient approach is to use a ring buffer of node we reuse as we scroll around if (bufferIdx >= $tmplBuffer.length) bufferIdx = 0; const $node = $tmplBuffer[bufferIdx]; bufferIdx += 1; // console.log($node); return $node; } let $tmplBuffer = []; let bufferIdx = 0; export function allocateMemory(size) { $tmplBuffer = Array.apply(null, {length: size}).map(() => $tmpl.cloneNode(true)) }