Mosaic extends KompElement
Mosiac is a managed CSS-Grid container that sizes to a grid
(columnCount × rowHeight). Each child cell declares its own
grid-area. When resizable or reorderable is on, drag interactions
update the affected cell's grid-area in place and run a "bump down"
pass: any cell that would overlap the moved/resized cell is shifted
down by enough rows to clear, cascading as needed.
Example
new Mosaic({
columnCount: 12,
rowHeight: 100,
resizable: true,
reorderable: true,
content: items.map((item, i) => createElement('div', {
style: { gridArea: `${i + 1} / 1 / span 1 / span 4` },
content: item.label
}))
})Constructor
new Mosaic(options)
options
:
Object
optionalcolumnCount
:
number
optionalNumber of grid columns.
rowHeight
:
number
optionalRow height in pixels. Defaults to offsetWidth / columnCount (square cells), tracked via ResizeObserver.
resizable
:
boolean
optionalRender per-cell drag handles for live resizing.
reorderable
:
boolean
optionalDrag a cell to reposition it on the grid; cells in the way bump down.
handleSelector
:
string
optionalWhen set, only pointerdown on a matching descendant of a cell starts a reorder. Has no effect when reorderable is false.
content
:
string
|
HTMLElement
|
Array
|
Object
optionalInitial children. Each must declare its own grid-area.
Instance Properties
cells
Direct children that aren't internal handle or drag-clone elements.
Static Properties
Attributes settable via constructor options. Each key is the attribute name and the value is a schema object describing how to handle it.
Example
static assignableAttributes = {
anchor: { type: 'HTMLElement', default: null, null: true },
placement: { type: 'string', default: 'bottom', null: false },
enabled: { type: 'boolean', default: true, null: false },
data: { type: 'array', default: [], null: false }
}Properties
type
:
string
|
Array.<string>
expected type(s): 'string', 'number', 'boolean', 'object', 'array', 'function', or a class/element name like 'HTMLElement'
default
:
*
default value when none is provided
null
:
boolean
whether null is an acceptable value
load
:
function
optionaloptional transform applied when reading the attribute value
Methods overridable via constructor options
Methods to auto-bind to this
Event names that can be bound via onEventName constructor options
CSS injected once per component via adoptedStyleSheets
CSS @layer name used to wrap the component's styles when injected
via adoptedStyleSheets. Set to a falsy value to disable layering.
Attributes to observe for changes. Triggers changed(attribute, was, now) and [attribute]Changed(was, now) callbacks.
Instance Methods
Cells abutting cell along edge whose perpendicular extent fits
inside the cell's. A split-resize moves these in lockstep with the
dragged edge — wider neighbors fall through to the collision cascade
so they're bumped instead of clamping the drag to zero.
Compare current cell grid-areas against startGridAreas and dispatch a
bubbling gridAreaChanged event on every cell whose grid-area differs.
event.detail = { gridArea, previousGridArea }. Called once at the end
of a resize or reorder — never on intermediate paints — so listeners can
react without per-frame overhead.
Read a cell's grid placement as a {rowStart, colStart, rowEnd, colEnd} object (grid line numbers).
Apply newGridArea to movedCell inside gridAreas and bump any cells
it collides with downward by enough rows to clear. Bumps cascade: a
bumped cell that now overlaps another also pushes it down. Columns
are preserved — only row lines move.
Listen for events on another element, automatically cleaned up when this component disconnects
Parameters
element
:
HTMLElement
element to listen on
eventType
:
string
event type
args
:
*
additional arguments passed to addEventListener
Called every time an observed attribute changes. Attribute must be listed in static watch.
Parameters
attribute
:
string
the attribute that changed
was
:
*
previous value
now
:
*
new value
Called when element is connected to the DOM
Called when element is disconnected from the DOM
Called once per instantiation, but only after element is connected to the DOM
Remove element. Fires remove, calls optional callback, removes from DOM, then fires removed.
Parameters
callback
:
function
optionalasync callback called between remove and removed
Returns
KompElement
this
Trigger an event on this element
Parameters
eventName
:
string
event name to trigger
args
:
*
additional arguments
Events
connect
Fired before the element is connected to the DOM (cancellable)
Fired after the element is connected to the DOM and initialized
Fired before the element is disconnected from the DOM (cancellable)
Fired after the element is disconnected from the DOM
remove
Fired before the element is removed (cancellable)
removed
Fired after the element is removed
reorder
Fired after a reorder. event.detail is { cell, gridArea }.
resize
Fired after a resize. event.detail is { cell, axis, edge, gridArea }.