MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / createWidgetDivs

Method createWidgetDivs

src/gridstack.ts:478–495  ·  view source on GitHub ↗

* Create the default grid item divs and content (possibly lazy loaded) by using GridStack.renderCB(). * * @param n GridStackNode definition containing widget configuration * @returns the created HTML element with proper grid item structure * * @example * const element = grid.create

(n: GridStackNode)

Source from the content-addressed store, hash-verified

476 * const element = grid.createWidgetDivs({ w: 2, h: 1, content: 'Hello World' });
477 */
478 public createWidgetDivs(n: GridStackNode): HTMLElement {
479 const el = Utils.createDiv(['grid-stack-item', this.opts.itemClass]);
480 const cont = Utils.createDiv(['grid-stack-item-content'], el);
481
482 if (Utils.lazyLoad(n)) {
483 if (!n.visibleObservable) {
484 n.visibleObservable = new IntersectionObserver(([entry]) => { if (entry.isIntersecting) {
485 n.visibleObservable?.disconnect();
486 delete n.visibleObservable;
487 GridStack.renderCB(cont, n);
488 n.grid?.prepareDragDrop(n.el);
489 }});
490 window.setTimeout(() => n.visibleObservable?.observe(el)); // wait until callee sets position attributes
491 }
492 } else GridStack.renderCB(cont, n);
493
494 return el;
495 }
496
497 /**
498 * Convert an existing gridItem element into a sub-grid with the given (optional) options, else inherit them

Callers 1

addWidgetMethod · 0.95

Calls 3

createDivMethod · 0.80
lazyLoadMethod · 0.80
prepareDragDropMethod · 0.80

Tested by

no test coverage detected