gridstack 12.2.2 → 12.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +3 -3
- package/dist/angular/README.md +2 -0
- package/dist/angular/esm2020/lib/base-widget.mjs +63 -7
- package/dist/angular/esm2020/lib/gridstack-item.component.mjs +33 -4
- package/dist/angular/esm2020/lib/gridstack.component.mjs +97 -16
- package/dist/angular/esm2020/lib/gridstack.module.mjs +25 -3
- package/dist/angular/esm2020/lib/types.mjs +2 -2
- package/dist/angular/fesm2015/gridstack-angular.mjs +191 -25
- package/dist/angular/fesm2015/gridstack-angular.mjs.map +1 -1
- package/dist/angular/fesm2020/gridstack-angular.mjs +192 -26
- package/dist/angular/fesm2020/gridstack-angular.mjs.map +1 -1
- package/dist/angular/lib/base-widget.d.ts +42 -5
- package/dist/angular/lib/gridstack-item.component.d.ts +49 -7
- package/dist/angular/lib/gridstack.component.d.ts +137 -22
- package/dist/angular/lib/gridstack.module.d.ts +23 -0
- package/dist/angular/lib/types.d.ts +32 -5
- package/dist/angular/package.json +1 -1
- package/dist/angular/src/base-widget.ts +68 -9
- package/dist/angular/src/gridstack-item.component.ts +49 -7
- package/dist/angular/src/gridstack.component.ts +154 -23
- package/dist/angular/src/gridstack.module.ts +24 -2
- package/dist/angular/src/types.ts +54 -0
- package/dist/dd-base-impl.d.ts +52 -3
- package/dist/dd-base-impl.js +41 -3
- package/dist/dd-base-impl.js.map +1 -1
- package/dist/dd-draggable.d.ts +2 -2
- package/dist/dd-draggable.js +4 -2
- package/dist/dd-draggable.js.map +1 -1
- package/dist/dd-droppable.d.ts +2 -2
- package/dist/dd-droppable.js +2 -2
- package/dist/dd-droppable.js.map +1 -1
- package/dist/dd-element.d.ts +2 -2
- package/dist/dd-element.js +2 -2
- package/dist/dd-element.js.map +1 -1
- package/dist/dd-gridstack.d.ts +54 -6
- package/dist/dd-gridstack.js +32 -2
- package/dist/dd-gridstack.js.map +1 -1
- package/dist/dd-manager.d.ts +29 -8
- package/dist/dd-manager.js +7 -3
- package/dist/dd-manager.js.map +1 -1
- package/dist/dd-resizable-handle.d.ts +2 -2
- package/dist/dd-resizable-handle.js +2 -2
- package/dist/dd-resizable-handle.js.map +1 -1
- package/dist/dd-resizable.d.ts +2 -2
- package/dist/dd-resizable.js +2 -2
- package/dist/dd-resizable.js.map +1 -1
- package/dist/dd-touch.d.ts +2 -2
- package/dist/dd-touch.js +2 -2
- package/dist/dd-touch.js.map +1 -1
- package/dist/gridstack-all.js +1 -1
- package/dist/gridstack-all.js.LICENSE.txt +2 -2
- package/dist/gridstack-all.js.map +1 -1
- package/dist/gridstack-engine.d.ts +241 -28
- package/dist/gridstack-engine.js +283 -32
- package/dist/gridstack-engine.js.map +1 -1
- package/dist/gridstack.css +2 -2
- package/dist/gridstack.d.ts +428 -83
- package/dist/gridstack.js +416 -81
- package/dist/gridstack.js.map +1 -1
- package/dist/src/gridstack.scss +2 -2
- package/dist/types.d.ts +130 -29
- package/dist/types.js +6 -3
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +208 -29
- package/dist/utils.js +278 -65
- package/dist/utils.js.map +1 -1
- package/doc/API.md +6198 -0
- package/package.json +10 -3
- package/doc/CHANGES.md +0 -962
- package/doc/README.md +0 -642
package/dist/gridstack.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* GridStack 12.
|
|
2
|
+
* GridStack 12.3.1
|
|
3
3
|
* https://gridstackjs.com/
|
|
4
4
|
*
|
|
5
|
-
* Copyright (c) 2021-
|
|
5
|
+
* Copyright (c) 2021-2025 Alain Dumesny
|
|
6
6
|
* see root license https://github.com/gridstack/gridstack.js/tree/master/LICENSE
|
|
7
7
|
*/
|
|
8
8
|
import { GridStackEngine } from './gridstack-engine';
|
|
@@ -23,6 +23,13 @@ export * from './types';
|
|
|
23
23
|
export * from './utils';
|
|
24
24
|
export * from './gridstack-engine';
|
|
25
25
|
export * from './dd-gridstack';
|
|
26
|
+
export * from './dd-manager';
|
|
27
|
+
export * from './dd-element';
|
|
28
|
+
export * from './dd-draggable';
|
|
29
|
+
export * from './dd-droppable';
|
|
30
|
+
export * from './dd-resizable';
|
|
31
|
+
export * from './dd-resizable-handle';
|
|
32
|
+
export * from './dd-base-impl';
|
|
26
33
|
/**
|
|
27
34
|
* Main gridstack class - you will need to call `GridStack.init()` first to initialize your grid.
|
|
28
35
|
* Note: your grid elements MUST have the following classes for the CSS layout to work:
|
|
@@ -132,7 +139,10 @@ class GridStack {
|
|
|
132
139
|
static registerEngine(engineClass) {
|
|
133
140
|
GridStack.engineClass = engineClass;
|
|
134
141
|
}
|
|
135
|
-
/**
|
|
142
|
+
/**
|
|
143
|
+
* @internal create placeholder DIV as needed
|
|
144
|
+
* @returns the placeholder element for indicating drop zones during drag operations
|
|
145
|
+
*/
|
|
136
146
|
get placeholder() {
|
|
137
147
|
if (!this._placeholder) {
|
|
138
148
|
this._placeholder = Utils.createDiv([this.opts.placeholderClass, gridDefaults.itemClass, this.opts.itemClass]);
|
|
@@ -315,6 +325,8 @@ class GridStack {
|
|
|
315
325
|
* @param w GridStackWidget definition. used MakeWidget(el) if you have dom element instead.
|
|
316
326
|
*/
|
|
317
327
|
addWidget(w) {
|
|
328
|
+
if (!w)
|
|
329
|
+
return;
|
|
318
330
|
if (typeof w === 'string') {
|
|
319
331
|
console.error('V11: GridStack.addWidget() does not support string anymore. see #2736');
|
|
320
332
|
return;
|
|
@@ -326,7 +338,7 @@ class GridStack {
|
|
|
326
338
|
let el;
|
|
327
339
|
let node = w;
|
|
328
340
|
node.grid = this;
|
|
329
|
-
if (node
|
|
341
|
+
if (node.el) {
|
|
330
342
|
el = node.el; // re-use element stored in the node
|
|
331
343
|
}
|
|
332
344
|
else if (GridStack.addRemoveCB) {
|
|
@@ -352,7 +364,15 @@ class GridStack {
|
|
|
352
364
|
this.makeWidget(el, w);
|
|
353
365
|
return el;
|
|
354
366
|
}
|
|
355
|
-
/**
|
|
367
|
+
/**
|
|
368
|
+
* Create the default grid item divs and content (possibly lazy loaded) by using GridStack.renderCB().
|
|
369
|
+
*
|
|
370
|
+
* @param n GridStackNode definition containing widget configuration
|
|
371
|
+
* @returns the created HTML element with proper grid item structure
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* const element = grid.createWidgetDivs({ w: 2, h: 1, content: 'Hello World' });
|
|
375
|
+
*/
|
|
356
376
|
createWidgetDivs(n) {
|
|
357
377
|
const el = Utils.createDiv(['grid-stack-item', this.opts.itemClass]);
|
|
358
378
|
const cont = Utils.createDiv(['grid-stack-item-content'], el);
|
|
@@ -448,7 +468,7 @@ class GridStack {
|
|
|
448
468
|
subGrid._isTemp = true; // prevent re-nesting as we add over
|
|
449
469
|
if (autoColumn)
|
|
450
470
|
subGrid._autoColumn = true;
|
|
451
|
-
// add the original content back as a child of
|
|
471
|
+
// add the original content back as a child of the newly created grid
|
|
452
472
|
if (saveContent) {
|
|
453
473
|
subGrid.makeWidget(newItem, newItemOpt);
|
|
454
474
|
}
|
|
@@ -498,11 +518,14 @@ class GridStack {
|
|
|
498
518
|
* @param saveGridOpt if true (default false), save the grid options itself, so you can call the new GridStack.addGrid()
|
|
499
519
|
* to recreate everything from scratch. GridStackOptions.children would then contain the widget list instead.
|
|
500
520
|
* @param saveCB callback for each node -> widget, so application can insert additional data to be saved into the widget data structure.
|
|
521
|
+
* @param columnSize if provided, the grid will be saved for the given column size (IFF we have matching internal saved layout, or current layout).
|
|
522
|
+
* Otherwise it will use the largest possible layout (say 12 even if rendering at 1 column) so we can restore to all layouts.
|
|
523
|
+
* Note: nested grids will ALWAYS save the container size to match overall layouts (parent + child) to be consistent.
|
|
501
524
|
* @returns list of widgets or full grid option, including .children list of widgets
|
|
502
525
|
*/
|
|
503
|
-
save(saveContent = true, saveGridOpt = false, saveCB = GridStack.saveCB) {
|
|
526
|
+
save(saveContent = true, saveGridOpt = false, saveCB = GridStack.saveCB, columnSize) {
|
|
504
527
|
// return copied GridStackWidget (with optionally .el) we can modify at will...
|
|
505
|
-
const list = this.engine.save(saveContent, saveCB);
|
|
528
|
+
const list = this.engine.save(saveContent, saveCB, columnSize);
|
|
506
529
|
// check for HTML content and nested grids
|
|
507
530
|
list.forEach(n => {
|
|
508
531
|
if (saveContent && n.el && !n.subGrid && !saveCB) { // sub-grid are saved differently, not plain content
|
|
@@ -515,9 +538,9 @@ class GridStack {
|
|
|
515
538
|
if (!saveContent && !saveCB) {
|
|
516
539
|
delete n.content;
|
|
517
540
|
}
|
|
518
|
-
// check for nested grid
|
|
541
|
+
// check for nested grid - make sure it saves to the given container size to be consistent
|
|
519
542
|
if (n.subGrid?.el) {
|
|
520
|
-
const listOrOpt = n.subGrid.save(saveContent, saveGridOpt, saveCB);
|
|
543
|
+
const listOrOpt = n.subGrid.save(saveContent, saveGridOpt, saveCB, n.w);
|
|
521
544
|
n.subGridOpts = (saveGridOpt ? listOrOpt : { children: listOrOpt });
|
|
522
545
|
delete n.subGrid;
|
|
523
546
|
}
|
|
@@ -559,20 +582,45 @@ class GridStack {
|
|
|
559
582
|
return list;
|
|
560
583
|
}
|
|
561
584
|
/**
|
|
562
|
-
*
|
|
585
|
+
* Load widgets from a list. This will call update() on each (matching by id) or add/remove widgets that are not there.
|
|
586
|
+
* Used to restore a grid layout for a saved layout list (see `save()`).
|
|
563
587
|
*
|
|
564
588
|
* @param items list of widgets definition to update/create
|
|
565
589
|
* @param addRemove boolean (default true) or callback method can be passed to control if and how missing widgets can be added/removed, giving
|
|
566
590
|
* the user control of insertion.
|
|
591
|
+
* @returns the grid instance for chaining
|
|
567
592
|
*
|
|
568
593
|
* @example
|
|
569
|
-
*
|
|
594
|
+
* // Basic usage with saved layout
|
|
595
|
+
* const savedLayout = grid.save(); // Save current layout
|
|
596
|
+
* // ... later restore it
|
|
597
|
+
* grid.load(savedLayout);
|
|
598
|
+
*
|
|
599
|
+
* // Load with custom add/remove callback
|
|
600
|
+
* grid.load(layout, (items, grid, add) => {
|
|
601
|
+
* if (add) {
|
|
602
|
+
* // Custom logic for adding new widgets
|
|
603
|
+
* items.forEach(item => {
|
|
604
|
+
* const el = document.createElement('div');
|
|
605
|
+
* el.innerHTML = item.content || '';
|
|
606
|
+
* grid.addWidget(el, item);
|
|
607
|
+
* });
|
|
608
|
+
* } else {
|
|
609
|
+
* // Custom logic for removing widgets
|
|
610
|
+
* items.forEach(item => grid.removeWidget(item.el));
|
|
611
|
+
* }
|
|
612
|
+
* });
|
|
613
|
+
*
|
|
614
|
+
* // Load without adding/removing missing widgets
|
|
615
|
+
* grid.load(layout, false);
|
|
616
|
+
*
|
|
617
|
+
* @see {@link http://gridstackjs.com/demo/serialization.html} for complete example
|
|
570
618
|
*/
|
|
571
619
|
load(items, addRemove = GridStack.addRemoveCB || true) {
|
|
572
620
|
items = Utils.cloneDeep(items); // so we can mod
|
|
573
621
|
const column = this.getColumn();
|
|
574
622
|
// make sure size 1x1 (default) is present as it may need to override current sizes
|
|
575
|
-
items.forEach(n => { n.w = n.w || 1; n.h = n.h || 1; });
|
|
623
|
+
items.forEach(n => { n.w = n.w || n.minW || 1; n.h = n.h || n.minH || 1; });
|
|
576
624
|
// sort items. those without coord will be appended last
|
|
577
625
|
items = Utils.sort(items);
|
|
578
626
|
this.engine.skipCacheUpdate = this._ignoreLayoutsNodeChange = true; // skip layout update
|
|
@@ -688,7 +736,17 @@ class GridStack {
|
|
|
688
736
|
return this;
|
|
689
737
|
}
|
|
690
738
|
/**
|
|
691
|
-
* Gets current cell height.
|
|
739
|
+
* Gets the current cell height in pixels. This takes into account the unit type and converts to pixels if necessary.
|
|
740
|
+
*
|
|
741
|
+
* @param forcePixel if true, forces conversion to pixels even when cellHeight is specified in other units
|
|
742
|
+
* @returns the cell height in pixels
|
|
743
|
+
*
|
|
744
|
+
* @example
|
|
745
|
+
* const height = grid.getCellHeight();
|
|
746
|
+
* console.log('Cell height:', height, 'px');
|
|
747
|
+
*
|
|
748
|
+
* // Force pixel conversion
|
|
749
|
+
* const pixelHeight = grid.getCellHeight(true);
|
|
692
750
|
*/
|
|
693
751
|
getCellHeight(forcePixel = false) {
|
|
694
752
|
if (this.opts.cellHeight && this.opts.cellHeight !== 'auto' &&
|
|
@@ -720,17 +778,21 @@ class GridStack {
|
|
|
720
778
|
return rows ? Math.round(this.el.getBoundingClientRect().height / rows) : this.opts.cellHeight;
|
|
721
779
|
}
|
|
722
780
|
/**
|
|
723
|
-
* Update current cell height - see `GridStackOptions.cellHeight` for format.
|
|
724
|
-
* This method rebuilds an internal CSS style sheet.
|
|
725
|
-
* Note: You can expect performance issues if call this method too often.
|
|
781
|
+
* Update current cell height - see `GridStackOptions.cellHeight` for format by updating eh Browser CSS variable.
|
|
726
782
|
*
|
|
727
|
-
* @param val the cell height.
|
|
728
|
-
*
|
|
783
|
+
* @param val the cell height. Options:
|
|
784
|
+
* - `undefined`: cells content will be made square (match width minus margin)
|
|
785
|
+
* - `0`: the CSS will be generated by the application instead
|
|
786
|
+
* - number: height in pixels
|
|
787
|
+
* - string: height with units (e.g., '70px', '5rem', '2em')
|
|
788
|
+
* @returns the grid instance for chaining
|
|
729
789
|
*
|
|
730
790
|
* @example
|
|
731
|
-
* grid.cellHeight(100);
|
|
732
|
-
* grid.cellHeight('70px');
|
|
733
|
-
* grid.cellHeight(
|
|
791
|
+
* grid.cellHeight(100); // 100px height
|
|
792
|
+
* grid.cellHeight('70px'); // explicit pixel height
|
|
793
|
+
* grid.cellHeight('5rem'); // relative to root font size
|
|
794
|
+
* grid.cellHeight(grid.cellWidth() * 1.2); // aspect ratio
|
|
795
|
+
* grid.cellHeight('auto'); // auto-size based on content
|
|
734
796
|
*/
|
|
735
797
|
cellHeight(val) {
|
|
736
798
|
// if not called internally, check if we're changing mode
|
|
@@ -762,6 +824,18 @@ class GridStack {
|
|
|
762
824
|
return this;
|
|
763
825
|
}
|
|
764
826
|
/** Gets current cell width. */
|
|
827
|
+
/**
|
|
828
|
+
* Gets the current cell width in pixels. This is calculated based on the grid container width divided by the number of columns.
|
|
829
|
+
*
|
|
830
|
+
* @returns the cell width in pixels
|
|
831
|
+
*
|
|
832
|
+
* @example
|
|
833
|
+
* const width = grid.cellWidth();
|
|
834
|
+
* console.log('Cell width:', width, 'px');
|
|
835
|
+
*
|
|
836
|
+
* // Use cell width to calculate widget dimensions
|
|
837
|
+
* const widgetWidth = width * 3; // For a 3-column wide widget
|
|
838
|
+
*/
|
|
765
839
|
cellWidth() {
|
|
766
840
|
return this._widthOrContainer() / this.getColumn();
|
|
767
841
|
}
|
|
@@ -798,11 +872,25 @@ class GridStack {
|
|
|
798
872
|
return false;
|
|
799
873
|
}
|
|
800
874
|
/**
|
|
801
|
-
*
|
|
802
|
-
*
|
|
803
|
-
*
|
|
875
|
+
* Re-layout grid items to reclaim any empty space. This is useful after removing widgets
|
|
876
|
+
* or when you want to optimize the layout.
|
|
877
|
+
*
|
|
878
|
+
* @param layout layout type. Options:
|
|
879
|
+
* - 'compact' (default): might re-order items to fill any empty space
|
|
880
|
+
* - 'list': keep the widget left->right order the same, even if that means leaving an empty slot if things don't fit
|
|
881
|
+
* @param doSort re-sort items first based on x,y position. Set to false to do your own sorting ahead (default: true)
|
|
882
|
+
* @returns the grid instance for chaining
|
|
883
|
+
*
|
|
884
|
+
* @example
|
|
885
|
+
* // Compact layout after removing widgets
|
|
886
|
+
* grid.removeWidget('.widget-to-remove');
|
|
887
|
+
* grid.compact();
|
|
888
|
+
*
|
|
889
|
+
* // Use list layout (preserve order)
|
|
890
|
+
* grid.compact('list');
|
|
804
891
|
*
|
|
805
|
-
*
|
|
892
|
+
* // Compact without sorting first
|
|
893
|
+
* grid.compact('compact', false);
|
|
806
894
|
*/
|
|
807
895
|
compact(layout = 'compact', doSort = true) {
|
|
808
896
|
this.engine.compact(layout, doSort);
|
|
@@ -810,11 +898,32 @@ class GridStack {
|
|
|
810
898
|
return this;
|
|
811
899
|
}
|
|
812
900
|
/**
|
|
813
|
-
*
|
|
901
|
+
* Set the number of columns in the grid. Will update existing widgets to conform to new number of columns,
|
|
814
902
|
* as well as cache the original layout so you can revert back to previous positions without loss.
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
*
|
|
903
|
+
*
|
|
904
|
+
* Requires `gridstack-extra.css` or `gridstack-extra.min.css` for [2-11] columns,
|
|
905
|
+
* else you will need to generate correct CSS.
|
|
906
|
+
* See: https://github.com/gridstack/gridstack.js#change-grid-columns
|
|
907
|
+
*
|
|
908
|
+
* @param column Integer > 0 (default 12)
|
|
909
|
+
* @param layout specify the type of re-layout that will happen. Options:
|
|
910
|
+
* - 'moveScale' (default): scale widget positions and sizes
|
|
911
|
+
* - 'move': keep widget sizes, only move positions
|
|
912
|
+
* - 'scale': keep widget positions, only scale sizes
|
|
913
|
+
* - 'none': don't change widget positions or sizes
|
|
914
|
+
* Note: items will never be outside of the current column boundaries.
|
|
915
|
+
* Ignored for `column=1` as we always want to vertically stack.
|
|
916
|
+
* @returns the grid instance for chaining
|
|
917
|
+
*
|
|
918
|
+
* @example
|
|
919
|
+
* // Change to 6 columns with default scaling
|
|
920
|
+
* grid.column(6);
|
|
921
|
+
*
|
|
922
|
+
* // Change to 4 columns, only move positions
|
|
923
|
+
* grid.column(4, 'move');
|
|
924
|
+
*
|
|
925
|
+
* // Single column layout (vertical stack)
|
|
926
|
+
* grid.column(1);
|
|
818
927
|
*/
|
|
819
928
|
column(column, layout = 'moveScale') {
|
|
820
929
|
if (!column || column < 1 || this.opts.column === column)
|
|
@@ -841,15 +950,42 @@ class GridStack {
|
|
|
841
950
|
return this;
|
|
842
951
|
}
|
|
843
952
|
/**
|
|
844
|
-
*
|
|
953
|
+
* Get the number of columns in the grid (default 12).
|
|
954
|
+
*
|
|
955
|
+
* @returns the current number of columns in the grid
|
|
956
|
+
*
|
|
957
|
+
* @example
|
|
958
|
+
* const columnCount = grid.getColumn(); // returns 12 by default
|
|
845
959
|
*/
|
|
846
960
|
getColumn() { return this.opts.column; }
|
|
847
|
-
/**
|
|
961
|
+
/**
|
|
962
|
+
* Returns an array of grid HTML elements (no placeholder) - used to iterate through our children in DOM order.
|
|
963
|
+
* This method excludes placeholder elements and returns only actual grid items.
|
|
964
|
+
*
|
|
965
|
+
* @returns array of GridItemHTMLElement instances representing all grid items
|
|
966
|
+
*
|
|
967
|
+
* @example
|
|
968
|
+
* const items = grid.getGridItems();
|
|
969
|
+
* items.forEach(item => {
|
|
970
|
+
* console.log('Item ID:', item.gridstackNode.id);
|
|
971
|
+
* });
|
|
972
|
+
*/
|
|
848
973
|
getGridItems() {
|
|
849
974
|
return Array.from(this.el.children)
|
|
850
975
|
.filter((el) => el.matches('.' + this.opts.itemClass) && !el.matches('.' + this.opts.placeholderClass));
|
|
851
976
|
}
|
|
852
|
-
/**
|
|
977
|
+
/**
|
|
978
|
+
* Returns true if change callbacks should be ignored due to column change, sizeToContent, loading, etc.
|
|
979
|
+
* This is useful for callers who want to implement dirty flag functionality.
|
|
980
|
+
*
|
|
981
|
+
* @returns true if change callbacks are currently being ignored
|
|
982
|
+
*
|
|
983
|
+
* @example
|
|
984
|
+
* if (!grid.isIgnoreChangeCB()) {
|
|
985
|
+
* // Process the change event
|
|
986
|
+
* console.log('Grid layout changed');
|
|
987
|
+
* }
|
|
988
|
+
*/
|
|
853
989
|
isIgnoreChangeCB() { return this._ignoreLayoutsNodeChange; }
|
|
854
990
|
/**
|
|
855
991
|
* Destroys a grid instance. DO NOT CALL any methods or access any vars after this as it will free up members.
|
|
@@ -881,7 +1017,15 @@ class GridStack {
|
|
|
881
1017
|
return this;
|
|
882
1018
|
}
|
|
883
1019
|
/**
|
|
884
|
-
*
|
|
1020
|
+
* Enable/disable floating widgets (default: `false`). When enabled, widgets can float up to fill empty spaces.
|
|
1021
|
+
* See [example](http://gridstackjs.com/demo/float.html)
|
|
1022
|
+
*
|
|
1023
|
+
* @param val true to enable floating, false to disable
|
|
1024
|
+
* @returns the grid instance for chaining
|
|
1025
|
+
*
|
|
1026
|
+
* @example
|
|
1027
|
+
* grid.float(true); // Enable floating
|
|
1028
|
+
* grid.float(false); // Disable floating (default)
|
|
885
1029
|
*/
|
|
886
1030
|
float(val) {
|
|
887
1031
|
if (this.opts.float !== val) {
|
|
@@ -891,7 +1035,13 @@ class GridStack {
|
|
|
891
1035
|
return this;
|
|
892
1036
|
}
|
|
893
1037
|
/**
|
|
894
|
-
*
|
|
1038
|
+
* Get the current float mode setting.
|
|
1039
|
+
*
|
|
1040
|
+
* @returns true if floating is enabled, false otherwise
|
|
1041
|
+
*
|
|
1042
|
+
* @example
|
|
1043
|
+
* const isFloating = grid.getFloat();
|
|
1044
|
+
* console.log('Floating enabled:', isFloating);
|
|
895
1045
|
*/
|
|
896
1046
|
getFloat() {
|
|
897
1047
|
return this.engine.float;
|
|
@@ -923,16 +1073,33 @@ class GridStack {
|
|
|
923
1073
|
const rowHeight = (box.height / parseInt(this.el.getAttribute('gs-current-row')));
|
|
924
1074
|
return { x: Math.floor(relativeLeft / columnWidth), y: Math.floor(relativeTop / rowHeight) };
|
|
925
1075
|
}
|
|
926
|
-
/**
|
|
1076
|
+
/**
|
|
1077
|
+
* Returns the current number of rows, which will be at least `minRow` if set.
|
|
1078
|
+
* The row count is based on the highest positioned widget in the grid.
|
|
1079
|
+
*
|
|
1080
|
+
* @returns the current number of rows in the grid
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* const rowCount = grid.getRow();
|
|
1084
|
+
* console.log('Grid has', rowCount, 'rows');
|
|
1085
|
+
*/
|
|
927
1086
|
getRow() {
|
|
928
1087
|
return Math.max(this.engine.getRow(), this.opts.minRow || 0);
|
|
929
1088
|
}
|
|
930
1089
|
/**
|
|
931
|
-
* Checks if specified area is empty.
|
|
932
|
-
*
|
|
933
|
-
* @param
|
|
934
|
-
* @param
|
|
935
|
-
* @param
|
|
1090
|
+
* Checks if the specified rectangular area is empty (no widgets occupy any part of it).
|
|
1091
|
+
*
|
|
1092
|
+
* @param x the x coordinate (column) of the area to check
|
|
1093
|
+
* @param y the y coordinate (row) of the area to check
|
|
1094
|
+
* @param w the width in columns of the area to check
|
|
1095
|
+
* @param h the height in rows of the area to check
|
|
1096
|
+
* @returns true if the area is completely empty, false if any widget overlaps
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* // Check if a 2x2 area at position (1,1) is empty
|
|
1100
|
+
* if (grid.isAreaEmpty(1, 1, 2, 2)) {
|
|
1101
|
+
* console.log('Area is available for placement');
|
|
1102
|
+
* }
|
|
936
1103
|
*/
|
|
937
1104
|
isAreaEmpty(x, y, w, h) {
|
|
938
1105
|
return this.engine.isAreaEmpty(x, y, w, h);
|
|
@@ -941,14 +1108,25 @@ class GridStack {
|
|
|
941
1108
|
* If you add elements to your grid by hand (or have some framework creating DOM), you have to tell gridstack afterwards to make them widgets.
|
|
942
1109
|
* If you want gridstack to add the elements for you, use `addWidget()` instead.
|
|
943
1110
|
* Makes the given element a widget and returns it.
|
|
1111
|
+
*
|
|
944
1112
|
* @param els widget or single selector to convert.
|
|
945
1113
|
* @param options widget definition to use instead of reading attributes or using default sizing values
|
|
1114
|
+
* @returns the converted GridItemHTMLElement
|
|
946
1115
|
*
|
|
947
1116
|
* @example
|
|
948
1117
|
* const grid = GridStack.init();
|
|
949
|
-
*
|
|
950
|
-
*
|
|
951
|
-
*
|
|
1118
|
+
*
|
|
1119
|
+
* // Create HTML content manually, possibly looking like:
|
|
1120
|
+
* // <div id="item-1" gs-x="0" gs-y="0" gs-w="3" gs-h="2"></div>
|
|
1121
|
+
* grid.el.innerHTML = '<div id="item-1" gs-w="3"></div><div id="item-2"></div>';
|
|
1122
|
+
*
|
|
1123
|
+
* // Convert existing elements to widgets
|
|
1124
|
+
* grid.makeWidget('#item-1'); // Uses gs-* attributes from DOM
|
|
1125
|
+
* grid.makeWidget('#item-2', {w: 2, h: 1, content: 'Hello World'});
|
|
1126
|
+
*
|
|
1127
|
+
* // Or pass DOM element directly
|
|
1128
|
+
* const element = document.getElementById('item-3');
|
|
1129
|
+
* grid.makeWidget(element, {x: 0, y: 1, w: 4, h: 2});
|
|
952
1130
|
*/
|
|
953
1131
|
makeWidget(els, options) {
|
|
954
1132
|
const el = GridStack.getElement(els);
|
|
@@ -1025,7 +1203,14 @@ class GridStack {
|
|
|
1025
1203
|
delete this._gsEventHandler[name];
|
|
1026
1204
|
return this;
|
|
1027
1205
|
}
|
|
1028
|
-
/**
|
|
1206
|
+
/**
|
|
1207
|
+
* Remove all event handlers from the grid. This is useful for cleanup when destroying a grid.
|
|
1208
|
+
*
|
|
1209
|
+
* @returns the grid instance for chaining
|
|
1210
|
+
*
|
|
1211
|
+
* @example
|
|
1212
|
+
* grid.offAll(); // Remove all event listeners
|
|
1213
|
+
*/
|
|
1029
1214
|
offAll() {
|
|
1030
1215
|
Object.keys(this._gsEventHandler).forEach((key) => this.off(key));
|
|
1031
1216
|
return this;
|
|
@@ -1196,9 +1381,30 @@ class GridStack {
|
|
|
1196
1381
|
return this;
|
|
1197
1382
|
}
|
|
1198
1383
|
/**
|
|
1199
|
-
* Updates widget position/size and other info.
|
|
1200
|
-
*
|
|
1201
|
-
*
|
|
1384
|
+
* Updates widget position/size and other info. This is used to change widget properties after creation.
|
|
1385
|
+
* Can update position, size, content, and other widget properties.
|
|
1386
|
+
*
|
|
1387
|
+
* Note: If you need to call this on all nodes, use load() instead which will update what changed.
|
|
1388
|
+
* Setting the same x,y for multiple items will be indeterministic and likely unwanted.
|
|
1389
|
+
*
|
|
1390
|
+
* @param els widget element(s) or selector to modify
|
|
1391
|
+
* @param opt new widget options (x,y,w,h, etc.). Only those set will be updated.
|
|
1392
|
+
* @returns the grid instance for chaining
|
|
1393
|
+
*
|
|
1394
|
+
* @example
|
|
1395
|
+
* // Update widget size and position
|
|
1396
|
+
* grid.update('.my-widget', { x: 2, y: 1, w: 3, h: 2 });
|
|
1397
|
+
*
|
|
1398
|
+
* // Update widget content
|
|
1399
|
+
* grid.update(widget, { content: '<p>New content</p>' });
|
|
1400
|
+
*
|
|
1401
|
+
* // Update multiple properties
|
|
1402
|
+
* grid.update('#my-widget', {
|
|
1403
|
+
* w: 4,
|
|
1404
|
+
* h: 3,
|
|
1405
|
+
* noResize: true,
|
|
1406
|
+
* locked: true
|
|
1407
|
+
* });
|
|
1202
1408
|
*/
|
|
1203
1409
|
update(els, opt) {
|
|
1204
1410
|
GridStack.getElements(els).forEach(el => {
|
|
@@ -1283,10 +1489,22 @@ class GridStack {
|
|
|
1283
1489
|
}
|
|
1284
1490
|
}
|
|
1285
1491
|
/**
|
|
1286
|
-
* Updates widget height to match the content height to avoid
|
|
1287
|
-
*
|
|
1288
|
-
*
|
|
1289
|
-
*
|
|
1492
|
+
* Updates widget height to match the content height to avoid vertical scrollbars or dead space.
|
|
1493
|
+
* This automatically adjusts the widget height based on its content size.
|
|
1494
|
+
*
|
|
1495
|
+
* Note: This assumes only 1 child under resizeToContentParent='.grid-stack-item-content'
|
|
1496
|
+
* (sized to gridItem minus padding) that represents the entire content size.
|
|
1497
|
+
*
|
|
1498
|
+
* @param el the grid item element to resize
|
|
1499
|
+
*
|
|
1500
|
+
* @example
|
|
1501
|
+
* // Resize a widget to fit its content
|
|
1502
|
+
* const widget = document.querySelector('.grid-stack-item');
|
|
1503
|
+
* grid.resizeToContent(widget);
|
|
1504
|
+
*
|
|
1505
|
+
* // This is commonly used with dynamic content:
|
|
1506
|
+
* widget.querySelector('.content').innerHTML = 'New longer content...';
|
|
1507
|
+
* grid.resizeToContent(widget);
|
|
1290
1508
|
*/
|
|
1291
1509
|
resizeToContent(el) {
|
|
1292
1510
|
if (!el)
|
|
@@ -1361,9 +1579,20 @@ class GridStack {
|
|
|
1361
1579
|
else
|
|
1362
1580
|
this.resizeToContent(el);
|
|
1363
1581
|
}
|
|
1364
|
-
/**
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
1582
|
+
/**
|
|
1583
|
+
* Rotate widgets by swapping their width and height. This is typically called when the user presses 'r' during dragging.
|
|
1584
|
+
* The rotation swaps the w/h dimensions and adjusts min/max constraints accordingly.
|
|
1585
|
+
*
|
|
1586
|
+
* @param els widget element(s) or selector to rotate
|
|
1587
|
+
* @param relative optional pixel coordinate relative to upper/left corner to rotate around (keeps that cell under cursor)
|
|
1588
|
+
* @returns the grid instance for chaining
|
|
1589
|
+
*
|
|
1590
|
+
* @example
|
|
1591
|
+
* // Rotate a specific widget
|
|
1592
|
+
* grid.rotate('.my-widget');
|
|
1593
|
+
*
|
|
1594
|
+
* // Rotate with relative positioning during drag
|
|
1595
|
+
* grid.rotate(widget, { left: 50, top: 30 });
|
|
1367
1596
|
*/
|
|
1368
1597
|
rotate(els, relative) {
|
|
1369
1598
|
GridStack.getElements(els).forEach(el => {
|
|
@@ -1387,8 +1616,19 @@ class GridStack {
|
|
|
1387
1616
|
return this;
|
|
1388
1617
|
}
|
|
1389
1618
|
/**
|
|
1390
|
-
* Updates the margins which will set all 4 sides at once - see `GridStackOptions.margin` for format options
|
|
1391
|
-
*
|
|
1619
|
+
* Updates the margins which will set all 4 sides at once - see `GridStackOptions.margin` for format options.
|
|
1620
|
+
* Supports CSS string format of 1, 2, or 4 values or a single number.
|
|
1621
|
+
*
|
|
1622
|
+
* @param value margin value - can be:
|
|
1623
|
+
* - Single number: `10` (applies to all sides)
|
|
1624
|
+
* - Two values: `'10px 20px'` (top/bottom, left/right)
|
|
1625
|
+
* - Four values: `'10px 20px 5px 15px'` (top, right, bottom, left)
|
|
1626
|
+
* @returns the grid instance for chaining
|
|
1627
|
+
*
|
|
1628
|
+
* @example
|
|
1629
|
+
* grid.margin(10); // 10px all sides
|
|
1630
|
+
* grid.margin('10px 20px'); // 10px top/bottom, 20px left/right
|
|
1631
|
+
* grid.margin('5px 10px 15px 20px'); // Different for each side
|
|
1392
1632
|
*/
|
|
1393
1633
|
margin(value) {
|
|
1394
1634
|
const isMultiValue = (typeof value === 'string' && value.split(' ').length > 1);
|
|
@@ -1404,7 +1644,20 @@ class GridStack {
|
|
|
1404
1644
|
this._initMargin();
|
|
1405
1645
|
return this;
|
|
1406
1646
|
}
|
|
1407
|
-
/**
|
|
1647
|
+
/**
|
|
1648
|
+
* Returns the current margin value as a number (undefined if the 4 sides don't match).
|
|
1649
|
+
* This only returns a number if all sides have the same margin value.
|
|
1650
|
+
*
|
|
1651
|
+
* @returns the margin value in pixels, or undefined if sides have different values
|
|
1652
|
+
*
|
|
1653
|
+
* @example
|
|
1654
|
+
* const margin = grid.getMargin();
|
|
1655
|
+
* if (margin !== undefined) {
|
|
1656
|
+
* console.log('Uniform margin:', margin, 'px');
|
|
1657
|
+
* } else {
|
|
1658
|
+
* console.log('Margins are different on different sides');
|
|
1659
|
+
* }
|
|
1660
|
+
*/
|
|
1408
1661
|
getMargin() { return this.opts.margin; }
|
|
1409
1662
|
/**
|
|
1410
1663
|
* Returns true if the height of the grid will be less than the vertical
|
|
@@ -1782,7 +2035,16 @@ class GridStack {
|
|
|
1782
2035
|
* but caused loading issues in prod - see https://github.com/gridstack/gridstack.js/issues/2039
|
|
1783
2036
|
* ===========================================================================================
|
|
1784
2037
|
*/
|
|
1785
|
-
/**
|
|
2038
|
+
/**
|
|
2039
|
+
* Get the global drag & drop implementation instance.
|
|
2040
|
+
* This provides access to the underlying drag & drop functionality.
|
|
2041
|
+
*
|
|
2042
|
+
* @returns the DDGridStack instance used for drag & drop operations
|
|
2043
|
+
*
|
|
2044
|
+
* @example
|
|
2045
|
+
* const dd = GridStack.getDD();
|
|
2046
|
+
* // Access drag & drop functionality
|
|
2047
|
+
*/
|
|
1786
2048
|
static getDD() {
|
|
1787
2049
|
return dd;
|
|
1788
2050
|
}
|
|
@@ -1809,10 +2071,22 @@ class GridStack {
|
|
|
1809
2071
|
});
|
|
1810
2072
|
}
|
|
1811
2073
|
/**
|
|
1812
|
-
* Enables/Disables dragging by the user
|
|
1813
|
-
*
|
|
1814
|
-
*
|
|
1815
|
-
*
|
|
2074
|
+
* Enables/Disables dragging by the user for specific grid elements.
|
|
2075
|
+
* For all items and future items, use enableMove() instead. No-op for static grids.
|
|
2076
|
+
*
|
|
2077
|
+
* Note: If you want to prevent an item from moving due to being pushed around by another
|
|
2078
|
+
* during collision, use the 'locked' property instead.
|
|
2079
|
+
*
|
|
2080
|
+
* @param els widget element(s) or selector to modify
|
|
2081
|
+
* @param val if true widget will be draggable, assuming the parent grid isn't noMove or static
|
|
2082
|
+
* @returns the grid instance for chaining
|
|
2083
|
+
*
|
|
2084
|
+
* @example
|
|
2085
|
+
* // Make specific widgets draggable
|
|
2086
|
+
* grid.movable('.my-widget', true);
|
|
2087
|
+
*
|
|
2088
|
+
* // Disable dragging for specific widgets
|
|
2089
|
+
* grid.movable('#fixed-widget', false);
|
|
1816
2090
|
*/
|
|
1817
2091
|
movable(els, val) {
|
|
1818
2092
|
if (this.opts.staticGrid)
|
|
@@ -1827,9 +2101,19 @@ class GridStack {
|
|
|
1827
2101
|
return this;
|
|
1828
2102
|
}
|
|
1829
2103
|
/**
|
|
1830
|
-
* Enables/Disables user resizing
|
|
1831
|
-
*
|
|
1832
|
-
*
|
|
2104
|
+
* Enables/Disables user resizing for specific grid elements.
|
|
2105
|
+
* For all items and future items, use enableResize() instead. No-op for static grids.
|
|
2106
|
+
*
|
|
2107
|
+
* @param els widget element(s) or selector to modify
|
|
2108
|
+
* @param val if true widget will be resizable, assuming the parent grid isn't noResize or static
|
|
2109
|
+
* @returns the grid instance for chaining
|
|
2110
|
+
*
|
|
2111
|
+
* @example
|
|
2112
|
+
* // Make specific widgets resizable
|
|
2113
|
+
* grid.resizable('.my-widget', true);
|
|
2114
|
+
*
|
|
2115
|
+
* // Disable resizing for specific widgets
|
|
2116
|
+
* grid.resizable('#fixed-size-widget', false);
|
|
1833
2117
|
*/
|
|
1834
2118
|
resizable(els, val) {
|
|
1835
2119
|
if (this.opts.staticGrid)
|
|
@@ -1846,12 +2130,24 @@ class GridStack {
|
|
|
1846
2130
|
/**
|
|
1847
2131
|
* Temporarily disables widgets moving/resizing.
|
|
1848
2132
|
* If you want a more permanent way (which freezes up resources) use `setStatic(true)` instead.
|
|
1849
|
-
*
|
|
2133
|
+
*
|
|
2134
|
+
* Note: This is a no-op for static grids.
|
|
2135
|
+
*
|
|
1850
2136
|
* This is a shortcut for:
|
|
2137
|
+
* ```typescript
|
|
2138
|
+
* grid.enableMove(false);
|
|
2139
|
+
* grid.enableResize(false);
|
|
2140
|
+
* ```
|
|
2141
|
+
*
|
|
2142
|
+
* @param recurse if true (default), sub-grids also get updated
|
|
2143
|
+
* @returns the grid instance for chaining
|
|
2144
|
+
*
|
|
1851
2145
|
* @example
|
|
1852
|
-
*
|
|
1853
|
-
*
|
|
1854
|
-
*
|
|
2146
|
+
* // Disable all interactions
|
|
2147
|
+
* grid.disable();
|
|
2148
|
+
*
|
|
2149
|
+
* // Disable only this grid, not sub-grids
|
|
2150
|
+
* grid.disable(false);
|
|
1855
2151
|
*/
|
|
1856
2152
|
disable(recurse = true) {
|
|
1857
2153
|
if (this.opts.staticGrid)
|
|
@@ -1863,12 +2159,23 @@ class GridStack {
|
|
|
1863
2159
|
}
|
|
1864
2160
|
/**
|
|
1865
2161
|
* Re-enables widgets moving/resizing - see disable().
|
|
1866
|
-
* Note: no-op for static
|
|
2162
|
+
* Note: This is a no-op for static grids.
|
|
2163
|
+
*
|
|
1867
2164
|
* This is a shortcut for:
|
|
2165
|
+
* ```typescript
|
|
2166
|
+
* grid.enableMove(true);
|
|
2167
|
+
* grid.enableResize(true);
|
|
2168
|
+
* ```
|
|
2169
|
+
*
|
|
2170
|
+
* @param recurse if true (default), sub-grids also get updated
|
|
2171
|
+
* @returns the grid instance for chaining
|
|
2172
|
+
*
|
|
1868
2173
|
* @example
|
|
1869
|
-
*
|
|
1870
|
-
*
|
|
1871
|
-
*
|
|
2174
|
+
* // Re-enable all interactions
|
|
2175
|
+
* grid.enable();
|
|
2176
|
+
*
|
|
2177
|
+
* // Enable only this grid, not sub-grids
|
|
2178
|
+
* grid.enable(false);
|
|
1872
2179
|
*/
|
|
1873
2180
|
enable(recurse = true) {
|
|
1874
2181
|
if (this.opts.staticGrid)
|
|
@@ -1879,8 +2186,22 @@ class GridStack {
|
|
|
1879
2186
|
return this;
|
|
1880
2187
|
}
|
|
1881
2188
|
/**
|
|
1882
|
-
* Enables/disables widget moving. No-op for static grids
|
|
1883
|
-
*
|
|
2189
|
+
* Enables/disables widget moving for all widgets. No-op for static grids.
|
|
2190
|
+
* Note: locally defined items (with noMove property) still override this setting.
|
|
2191
|
+
*
|
|
2192
|
+
* @param doEnable if true widgets will be movable, if false moving is disabled
|
|
2193
|
+
* @param recurse if true (default), sub-grids also get updated
|
|
2194
|
+
* @returns the grid instance for chaining
|
|
2195
|
+
*
|
|
2196
|
+
* @example
|
|
2197
|
+
* // Enable moving for all widgets
|
|
2198
|
+
* grid.enableMove(true);
|
|
2199
|
+
*
|
|
2200
|
+
* // Disable moving for all widgets
|
|
2201
|
+
* grid.enableMove(false);
|
|
2202
|
+
*
|
|
2203
|
+
* // Enable only this grid, not sub-grids
|
|
2204
|
+
* grid.enableMove(true, false);
|
|
1884
2205
|
*/
|
|
1885
2206
|
enableMove(doEnable, recurse = true) {
|
|
1886
2207
|
if (this.opts.staticGrid)
|
|
@@ -1894,8 +2215,22 @@ class GridStack {
|
|
|
1894
2215
|
return this;
|
|
1895
2216
|
}
|
|
1896
2217
|
/**
|
|
1897
|
-
* Enables/disables widget resizing. No-op for static grids.
|
|
1898
|
-
*
|
|
2218
|
+
* Enables/disables widget resizing for all widgets. No-op for static grids.
|
|
2219
|
+
* Note: locally defined items (with noResize property) still override this setting.
|
|
2220
|
+
*
|
|
2221
|
+
* @param doEnable if true widgets will be resizable, if false resizing is disabled
|
|
2222
|
+
* @param recurse if true (default), sub-grids also get updated
|
|
2223
|
+
* @returns the grid instance for chaining
|
|
2224
|
+
*
|
|
2225
|
+
* @example
|
|
2226
|
+
* // Enable resizing for all widgets
|
|
2227
|
+
* grid.enableResize(true);
|
|
2228
|
+
*
|
|
2229
|
+
* // Disable resizing for all widgets
|
|
2230
|
+
* grid.enableResize(false);
|
|
2231
|
+
*
|
|
2232
|
+
* // Enable only this grid, not sub-grids
|
|
2233
|
+
* grid.enableResize(true, false);
|
|
1899
2234
|
*/
|
|
1900
2235
|
enableResize(doEnable, recurse = true) {
|
|
1901
2236
|
if (this.opts.staticGrid)
|
|
@@ -2290,8 +2625,7 @@ class GridStack {
|
|
|
2290
2625
|
else {
|
|
2291
2626
|
Utils.removePositioningStyles(target);
|
|
2292
2627
|
if (node._temporaryRemoved) {
|
|
2293
|
-
//
|
|
2294
|
-
Utils.copyPos(node, node._orig); // @ts-ignore
|
|
2628
|
+
// use last position we were at (not _orig as we may have pushed others and moved) and add it back
|
|
2295
2629
|
this._writePosAttr(target, node);
|
|
2296
2630
|
this.engine.addNode(node);
|
|
2297
2631
|
}
|
|
@@ -2530,6 +2864,7 @@ GridStack.resizeToContentParent = '.grid-stack-item-content';
|
|
|
2530
2864
|
GridStack.Utils = Utils;
|
|
2531
2865
|
/** scoping so users can call new GridStack.Engine(12) for example */
|
|
2532
2866
|
GridStack.Engine = GridStackEngine;
|
|
2533
|
-
|
|
2867
|
+
/** @internal current version compiled in code */
|
|
2868
|
+
GridStack.GDRev = '12.3.1';
|
|
2534
2869
|
export { GridStack };
|
|
2535
2870
|
//# sourceMappingURL=gridstack.js.map
|