From 7053ec67f677a43b5bfc6efd828ef35e5b7a3319 Mon Sep 17 00:00:00 2001 From: Alain Dumesny Date: Sun, 17 Aug 2025 19:18:32 -0700 Subject: [PATCH 1/3] doc fixes --- .github/workflows/deploy-docs.yml | 4 ++-- tsconfig.docs.json | 18 ++++++++++++++++++ typedoc.html.json | 1 + typedoc.json | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tsconfig.docs.json diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index a7063434f..d1332c7d1 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -39,10 +39,10 @@ jobs: run: | grunt webpack - tsc --stripInternal + tsc --project tsconfig.docs.json --stripInternal - name: Generate all documentation - run: yarn doc:all + run: yarn doc - name: Prepare deployment structure run: | diff --git a/tsconfig.docs.json b/tsconfig.docs.json new file mode 100644 index 000000000..04a20945b --- /dev/null +++ b/tsconfig.docs.json @@ -0,0 +1,18 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "skipLibCheck": true, + "types": [] + }, + "include": [ + "./src/**/*.ts" + ], + "exclude": [ + "./src/**/*.spec.ts", + "./src/**/*.test.ts", + "./spec/**/*", + "./angular/**/*", + "./demo/**/*", + "./node_modules/**/*" + ] +} diff --git a/typedoc.html.json b/typedoc.html.json index 46651938d..cb6c98586 100644 --- a/typedoc.html.json +++ b/typedoc.html.json @@ -1,6 +1,7 @@ { "$schema": "https://typedoc.org/schema.json", "entryPoints": ["src/gridstack.ts"], + "tsconfig": "tsconfig.docs.json", "excludeExternals": false, "out": "doc/html", "exclude": [ diff --git a/typedoc.json b/typedoc.json index 9b949f035..16a413246 100644 --- a/typedoc.json +++ b/typedoc.json @@ -1,6 +1,7 @@ { "$schema": "https://typedoc.org/schema.json", "entryPoints": ["src/gridstack.ts"], + "tsconfig": "tsconfig.docs.json", "excludeExternals": false, "out": "doc", "plugin": ["typedoc-plugin-markdown"], From 304ffb1db8f156ca27d7db7bde12c20d7d2ae262 Mon Sep 17 00:00:00 2001 From: Alain Dumesny Date: Sun, 17 Aug 2025 19:28:22 -0700 Subject: [PATCH 2/3] fix sync-docs workflow to work on adumesny/gridstack.js fork - Changed repository check from gridstack/gridstack.js to adumesny/gridstack.js - Fixed doc path from docs/html to doc/html to match expected structure - This will enable automatic syncing of documentation from master to gh-pages --- .github/workflows/sync-docs.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/sync-docs.yml b/.github/workflows/sync-docs.yml index 31fe83318..99bef399c 100644 --- a/.github/workflows/sync-docs.yml +++ b/.github/workflows/sync-docs.yml @@ -12,7 +12,7 @@ on: jobs: sync-docs: runs-on: ubuntu-latest - if: github.repository == 'gridstack/gridstack.js' + if: github.repository == 'adumesny/gridstack.js' steps: - name: Checkout master branch @@ -53,19 +53,17 @@ jobs: run: | echo "Syncing main library documentation..." - # Remove existing docs directory if it exists - if [ -d "docs/html" ]; then - rm -rf docs/html + # Remove existing doc/html directory if it exists + if [ -d "doc/html" ]; then + rm -rf doc/html fi # Extract docs from master branch using git archive - mkdir -p docs + mkdir -p doc git archive master doc/html | tar -xf - - mv doc/html docs/html - rm -rf doc # Add changes - git add docs/html + git add doc/html - name: Sync Angular documentation if: steps.check-docs.outputs.angular_docs == 'true' From d3e2e061acec4ff7c629eb574054f86536a6322b Mon Sep 17 00:00:00 2001 From: Alain Dumesny Date: Sun, 17 Aug 2025 20:12:11 -0700 Subject: [PATCH 3/3] better code coverage --- doc/API.md | 100 +++--- spec/gridstack-spec.ts | 33 -- spec/utils-spec.ts | 683 +++++++++++++++++++++++++++++++++++++++++ src/gridstack.ts | 19 +- src/utils.ts | 58 ++-- 5 files changed, 760 insertions(+), 133 deletions(-) diff --git a/doc/API.md b/doc/API.md index 737b25749..3967cb62a 100644 --- a/doc/API.md +++ b/doc/API.md @@ -113,7 +113,7 @@ Construct a grid item from the given element and options protected _updateResizeEvent(forceRemove): GridStack; ``` -Defined in: [gridstack.ts:2091](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2091) +Defined in: [gridstack.ts:2083](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2083) add or remove the grid element size event handler @@ -133,7 +133,7 @@ add or remove the grid element size event handler protected _widthOrContainer(forBreakpoint): number; ``` -Defined in: [gridstack.ts:954](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L954) +Defined in: [gridstack.ts:955](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L955) return our expected width (or parent) , and optionally of window for dynamic column check @@ -286,7 +286,7 @@ const widgetWidth = width * 3; // For a 3-column wide widget protected checkDynamicColumn(): boolean; ``` -Defined in: [gridstack.ts:960](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L960) +Defined in: [gridstack.ts:962](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L962) checks for dynamic column count for our current size, returning true if changed @@ -300,7 +300,7 @@ checks for dynamic column count for our current size, returning true if changed column(column, layout): GridStack; ``` -Defined in: [gridstack.ts:1039](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1039) +Defined in: [gridstack.ts:1041](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1041) Set the number of columns in the grid. Will update existing widgets to conform to new number of columns, as well as cache the original layout so you can revert back to previous positions without loss. @@ -335,25 +335,13 @@ grid.column(4, 'move'); grid.column(1); ``` -##### commit() - -```ts -commit(): GridStack; -``` - -Defined in: [gridstack.ts:3020](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L3020) - -###### Returns - -[`GridStack`](#gridstack-1) - ##### compact() ```ts compact(layout, doSort): GridStack; ``` -Defined in: [gridstack.ts:1005](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1005) +Defined in: [gridstack.ts:1007](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1007) Re-layout grid items to reclaim any empty space. This is useful after removing widgets or when you want to optimize the layout. @@ -419,7 +407,7 @@ const element = grid.createWidgetDivs({ w: 2, h: 1, content: 'Hello World' }); destroy(removeDOM): GridStack; ``` -Defined in: [gridstack.ts:1113](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1113) +Defined in: [gridstack.ts:1115](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1115) Destroys a grid instance. DO NOT CALL any methods or access any vars after this as it will free up members. @@ -439,7 +427,7 @@ Destroys a grid instance. DO NOT CALL any methods or access any vars after this disable(recurse): GridStack; ``` -Defined in: [gridstack.ts:2292](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2292) +Defined in: [gridstack.ts:2284](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2284) Temporarily disables widgets moving/resizing. If you want a more permanent way (which freezes up resources) use `setStatic(true)` instead. @@ -480,7 +468,7 @@ grid.disable(false); enable(recurse): GridStack; ``` -Defined in: [gridstack.ts:2319](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2319) +Defined in: [gridstack.ts:2311](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2311) Re-enables widgets moving/resizing - see disable(). Note: This is a no-op for static grids. @@ -519,7 +507,7 @@ grid.enable(false); enableMove(doEnable, recurse): GridStack; ``` -Defined in: [gridstack.ts:2345](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2345) +Defined in: [gridstack.ts:2337](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2337) Enables/disables widget moving for all widgets. No-op for static grids. Note: locally defined items (with noMove property) still override this setting. @@ -556,7 +544,7 @@ grid.enableMove(true, false); enableResize(doEnable, recurse): GridStack; ``` -Defined in: [gridstack.ts:2373](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2373) +Defined in: [gridstack.ts:2365](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2365) Enables/disables widget resizing for all widgets. No-op for static grids. Note: locally defined items (with noResize property) still override this setting. @@ -593,7 +581,7 @@ grid.enableResize(true, false); float(val): GridStack; ``` -Defined in: [gridstack.ts:1147](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1147) +Defined in: [gridstack.ts:1149](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1149) Enable/disable floating widgets (default: `false`). When enabled, widgets can float up to fill empty spaces. See [example](http://gridstackjs.com/demo/float.html) @@ -623,7 +611,7 @@ grid.float(false); // Disable floating (default) getCellFromPixel(position, useDocRelative): CellPosition; ``` -Defined in: [gridstack.ts:1177](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1177) +Defined in: [gridstack.ts:1179](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1179) Get the position of the cell under a pixel on screen. @@ -676,7 +664,7 @@ const pixelHeight = grid.getCellHeight(true); getColumn(): number; ``` -Defined in: [gridstack.ts:1076](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1076) +Defined in: [gridstack.ts:1078](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1078) Get the number of columns in the grid (default 12). @@ -698,7 +686,7 @@ const columnCount = grid.getColumn(); // returns 12 by default static getDD(): DDGridStack; ``` -Defined in: [gridstack.ts:2189](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2189) +Defined in: [gridstack.ts:2181](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2181) Get the global drag & drop implementation instance. This provides access to the underlying drag & drop functionality. @@ -722,7 +710,7 @@ const dd = GridStack.getDD(); getFloat(): boolean; ``` -Defined in: [gridstack.ts:1164](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1164) +Defined in: [gridstack.ts:1166](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1166) Get the current float mode setting. @@ -745,7 +733,7 @@ console.log('Floating enabled:', isFloating); getGridItems(): GridItemHTMLElement[]; ``` -Defined in: [gridstack.ts:1090](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1090) +Defined in: [gridstack.ts:1092](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1092) Returns an array of grid HTML elements (no placeholder) - used to iterate through our children in DOM order. This method excludes placeholder elements and returns only actual grid items. @@ -771,7 +759,7 @@ items.forEach(item => { getMargin(): number; ``` -Defined in: [gridstack.ts:1788](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1788) +Defined in: [gridstack.ts:1790](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1790) Returns the current margin value as a number (undefined if the 4 sides don't match). This only returns a number if all sides have the same margin value. @@ -799,7 +787,7 @@ if (margin !== undefined) { getRow(): number; ``` -Defined in: [gridstack.ts:1207](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1207) +Defined in: [gridstack.ts:1209](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1209) Returns the current number of rows, which will be at least `minRow` if set. The row count is based on the highest positioned widget in the grid. @@ -887,7 +875,7 @@ isAreaEmpty( h): boolean; ``` -Defined in: [gridstack.ts:1226](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1226) +Defined in: [gridstack.ts:1228](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1228) Checks if the specified rectangular area is empty (no widgets occupy any part of it). @@ -921,7 +909,7 @@ if (grid.isAreaEmpty(1, 1, 2, 2)) { isIgnoreChangeCB(): boolean; ``` -Defined in: [gridstack.ts:1107](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1107) +Defined in: [gridstack.ts:1109](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1109) Returns true if change callbacks should be ignored due to column change, sizeToContent, loading, etc. This is useful for callers who want to implement dirty flag functionality. @@ -1032,7 +1020,7 @@ newly created grid makeWidget(els, options?): GridItemHTMLElement; ``` -Defined in: [gridstack.ts:1254](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1254) +Defined in: [gridstack.ts:1256](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1256) 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. If you want gridstack to add the elements for you, use `addWidget()` instead. @@ -1075,7 +1063,7 @@ grid.makeWidget(element, {x: 0, y: 1, w: 4, h: 2}); margin(value): GridStack; ``` -Defined in: [gridstack.ts:1759](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1759) +Defined in: [gridstack.ts:1761](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1761) Updates the margins which will set all 4 sides at once - see `GridStackOptions.margin` for format options. Supports CSS string format of 1, 2, or 4 values or a single number. @@ -1106,7 +1094,7 @@ grid.margin('5px 10px 15px 20px'); // Different for each side movable(els, val): GridStack; ``` -Defined in: [gridstack.ts:2233](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2233) +Defined in: [gridstack.ts:2225](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2225) Enables/Disables dragging by the user for specific grid elements. For all items and future items, use enableMove() instead. No-op for static grids. @@ -1143,7 +1131,7 @@ grid.movable('#fixed-widget', false); off(name): GridStack; ``` -Defined in: [gridstack.ts:1350](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1350) +Defined in: [gridstack.ts:1352](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1352) unsubscribe from the 'on' event GridStackEvent @@ -1163,7 +1151,7 @@ unsubscribe from the 'on' event GridStackEvent offAll(): GridStack; ``` -Defined in: [gridstack.ts:1377](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1377) +Defined in: [gridstack.ts:1379](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1379) Remove all event handlers from the grid. This is useful for cleanup when destroying a grid. @@ -1187,7 +1175,7 @@ grid.offAll(); // Remove all event listeners on(name, callback): GridStack; ``` -Defined in: [gridstack.ts:1313](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1313) +Defined in: [gridstack.ts:1315](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1315) Register event handler for grid events. You can call this on a single event name, or space separated list. @@ -1238,7 +1226,7 @@ grid.on('added', (event, items) => { on(name, callback): GridStack; ``` -Defined in: [gridstack.ts:1314](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1314) +Defined in: [gridstack.ts:1316](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1316) Register event handler for grid events. You can call this on a single event name, or space separated list. @@ -1289,7 +1277,7 @@ grid.on('added', (event, items) => { on(name, callback): GridStack; ``` -Defined in: [gridstack.ts:1315](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1315) +Defined in: [gridstack.ts:1317](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1317) Register event handler for grid events. You can call this on a single event name, or space separated list. @@ -1340,7 +1328,7 @@ grid.on('added', (event, items) => { on(name, callback): GridStack; ``` -Defined in: [gridstack.ts:1316](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1316) +Defined in: [gridstack.ts:1318](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1318) Register event handler for grid events. You can call this on a single event name, or space separated list. @@ -1391,7 +1379,7 @@ grid.on('added', (event, items) => { on(name, callback): GridStack; ``` -Defined in: [gridstack.ts:1317](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1317) +Defined in: [gridstack.ts:1319](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1319) Register event handler for grid events. You can call this on a single event name, or space separated list. @@ -1442,7 +1430,7 @@ grid.on('added', (event, items) => { onResize(clientWidth): GridStack; ``` -Defined in: [gridstack.ts:2030](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2030) +Defined in: [gridstack.ts:2022](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2022) called when we are being resized - check if the one Column Mode needs to be turned on/off and remember the prev columns we used, or get our count from parent, as well as check for cellHeight==='auto' (square) @@ -1464,7 +1452,7 @@ or `sizeToContent` gridItem options. prepareDragDrop(el, force?): GridStack; ``` -Defined in: [gridstack.ts:2716](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2716) +Defined in: [gridstack.ts:2708](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2708) prepares the element for drag&drop - this is normally called by makeWidget() unless are are delay loading @@ -1507,7 +1495,7 @@ replace just one instance. removeAll(removeDOM, triggerEvent): GridStack; ``` -Defined in: [gridstack.ts:1426](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1426) +Defined in: [gridstack.ts:1428](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1428) Removes all widgets from the grid. @@ -1552,7 +1540,7 @@ removeWidget( triggerEvent): GridStack; ``` -Defined in: [gridstack.ts:1388](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1388) +Defined in: [gridstack.ts:1390](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1390) Removes widget from the grid. @@ -1574,7 +1562,7 @@ Removes widget from the grid. resizable(els, val): GridStack; ``` -Defined in: [gridstack.ts:2259](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2259) +Defined in: [gridstack.ts:2251](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2251) Enables/Disables user resizing for specific grid elements. For all items and future items, use enableResize() instead. No-op for static grids. @@ -1608,7 +1596,7 @@ grid.resizable('#fixed-size-widget', false); resizeToContent(el): void; ``` -Defined in: [gridstack.ts:1649](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1649) +Defined in: [gridstack.ts:1651](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1651) Updates widget height to match the content height to avoid vertical scrollbars or dead space. This automatically adjusts the widget height based on its content size. @@ -1644,7 +1632,7 @@ grid.resizeToContent(widget); rotate(els, relative?): GridStack; ``` -Defined in: [gridstack.ts:1724](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1724) +Defined in: [gridstack.ts:1726](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1726) Rotate widgets by swapping their width and height. This is typically called when the user presses 'r' during dragging. The rotation swaps the w/h dimensions and adjusts min/max constraints accordingly. @@ -1710,7 +1698,7 @@ list of widgets or full grid option, including .children list of widgets setAnimation(doAnimate, delay?): GridStack; ``` -Defined in: [gridstack.ts:1445](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1445) +Defined in: [gridstack.ts:1447](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1447) Toggle the grid animation state. Toggles the `grid-stack-animate` class. @@ -1734,7 +1722,7 @@ setStatic( recurse): GridStack; ``` -Defined in: [gridstack.ts:1468](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1468) +Defined in: [gridstack.ts:1470](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1470) Toggle the grid static state, which permanently removes/add Drag&Drop support, unlike disable()/enable() that just turns it off/on. Also toggle the grid-stack-static class. @@ -1761,7 +1749,7 @@ static setupDragIn( root?): void; ``` -Defined in: [gridstack.ts:2202](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2202) +Defined in: [gridstack.ts:2194](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2194) call to setup dragging in from the outside (say toolbar), by specifying the class selection and options. Called during GridStack.init() as options, but can also be called directly (last param are used) in case the toolbar @@ -1786,7 +1774,7 @@ is dynamically create and needs to be set later. protected triggerEvent(event, target): void; ``` -Defined in: [gridstack.ts:2970](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2970) +Defined in: [gridstack.ts:2962](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L2962) call given event callback on our main top-most grid (if we're nested) @@ -1807,7 +1795,7 @@ call given event callback on our main top-most grid (if we're nested) update(els, opt): GridStack; ``` -Defined in: [gridstack.ts:1545](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1545) +Defined in: [gridstack.ts:1547](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1547) Updates widget position/size and other info. This is used to change widget properties after creation. Can update position, size, content, and other widget properties. @@ -1852,7 +1840,7 @@ grid.update('#my-widget', { updateOptions(o): GridStack; ``` -Defined in: [gridstack.ts:1486](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1486) +Defined in: [gridstack.ts:1488](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1488) Updates the passed in options on the grid (similar to update(widget) for for the grid options). @@ -1872,7 +1860,7 @@ Updates the passed in options on the grid (similar to update(widget) for for the willItFit(node): boolean; ``` -Defined in: [gridstack.ts:1802](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1802) +Defined in: [gridstack.ts:1804](https://github.com/adumesny/gridstack.js/blob/master/src/gridstack.ts#L1804) Returns true if the height of the grid will be less than the vertical constraint. Always returns true if grid doesn't have height constraint. diff --git a/spec/gridstack-spec.ts b/spec/gridstack-spec.ts index cadf6babf..a950941f0 100644 --- a/spec/gridstack-spec.ts +++ b/spec/gridstack-spec.ts @@ -1841,39 +1841,6 @@ describe('gridstack >', () => { }); }); - // ..and finally track log warnings at the end, instead of displaying them.... - describe('obsolete warnings >', () => { - console.warn = vi.fn(); // track warnings instead of displaying them - beforeEach(() => { - document.body.insertAdjacentHTML('afterbegin', gridstackHTML); - }); - afterEach(() => { - document.body.removeChild(document.getElementById('gs-cont')); - }); - it('willItFit() legacy >', () => { - grid = GridStack.init({maxRow: 5}); - expect((grid as any).willItFit(0, 0, 1, 3, false)).toBe(true); - expect((grid as any).willItFit(0, 0, 1, 4, false)).toBe(false); - }); - it('warning if OLD commit() is called >', () => { - grid = GridStack.init(); - grid.batchUpdate(true); - expect(grid.engine.batchMode).toBe(true); - grid.commit(); // old API - expect(grid.engine.batchMode).toBe(false); - // expect(console.warn).toHaveBeenCalledWith('gridstack.js: Function `setGridWidth` is deprecated in v0.5.3 and has been replaced with `column`. It will be **completely** removed in v1.0'); - }); - - /* saving as example - it('warning if OLD setGridWidth is called >', () => { - let grid: any = GridStack.init(); - grid.setGridWidth(11); // old 0.5.2 API - expect(grid.getColumn()).toBe(11); - expect(console.warn).toHaveBeenCalledWith('gridstack.js: Function `setGridWidth` is deprecated in v0.5.3 and has been replaced with `column`. It will be **completely** removed in v1.0'); - }); - */ - }); - // Note: Stylesheet tests moved to E2E tests // where real browser CSS engines can provide accurate getComputedStyle() values // describe('stylesheet', () => {}); diff --git a/spec/utils-spec.ts b/spec/utils-spec.ts index cf929a49b..ed9e3d464 100644 --- a/spec/utils-spec.ts +++ b/spec/utils-spec.ts @@ -252,4 +252,687 @@ describe('gridstack utils', () => { expect(a).toEqual({obj1: {nested: {second: 2}}}); }); }); + + // Obsolete functions are tested indirectly through gridstack usage + + describe('getElements', () => { + beforeEach(() => { + document.body.innerHTML = ` +
numeric id
+
regular id
+
class element
+
another class
+
+ `; + }); + + it('should get element by numeric id', () => { + const elements = Utils.getElements('123'); + expect(elements.length).toBe(1); + expect(elements[0].textContent).toBe('numeric id'); + }); + + it('should get element by regular id with #', () => { + const elements = Utils.getElements('#regular-id'); + expect(elements.length).toBe(1); + expect(elements[0].textContent).toBe('regular id'); + }); + + it('should get elements by class with .', () => { + const elements = Utils.getElements('.test-class'); + expect(elements.length).toBe(1); + expect(elements[0].textContent).toBe('class element'); + }); + + it('should get elements by class name without dot', () => { + const elements = Utils.getElements('test-class'); + expect(elements.length).toBe(1); + expect(elements[0].textContent).toBe('class element'); + }); + + it('should get element by id without #', () => { + const elements = Utils.getElements('regular-id'); + expect(elements.length).toBe(1); + expect(elements[0].textContent).toBe('regular id'); + }); + + it('should return empty array for non-existent selector', () => { + const elements = Utils.getElements('non-existent'); + expect(elements.length).toBe(0); + }); + + it('should return the element itself if passed', () => { + const el = document.getElementById('regular-id'); + const elements = Utils.getElements(el); + expect(elements.length).toBe(1); + expect(elements[0]).toBe(el); + }); + }); + + describe('getElement', () => { + beforeEach(() => { + document.body.innerHTML = ` +
numeric id
+
regular id
+
class element
+
attribute element
+ `; + }); + + it('should get element by id with #', () => { + const element = Utils.getElement('#regular-id'); + expect(element.textContent).toBe('regular id'); + }); + + it('should get element by numeric id', () => { + const element = Utils.getElement('123'); + expect(element.textContent).toBe('numeric id'); + }); + + it('should get element by class with .', () => { + const element = Utils.getElement('.test-class'); + expect(element.textContent).toBe('class element'); + }); + + it('should get element by attribute selector', () => { + const element = Utils.getElement('[data-test="attribute"]'); + expect(element.textContent).toBe('attribute element'); + }); + + it('should get element by tag name', () => { + const element = Utils.getElement('div'); + expect(element.tagName).toBe('DIV'); + }); + + it('should return null for empty string', () => { + const element = Utils.getElement(''); + expect(element).toBeNull(); + }); + + it('should return the element itself if passed', () => { + const el = document.getElementById('regular-id'); + const element = Utils.getElement(el); + expect(element).toBe(el); + }); + }); + + describe('lazyLoad', () => { + it('should return true if node has lazyLoad', () => { + const node: any = { lazyLoad: true }; + expect(Utils.lazyLoad(node)).toBe(true); + }); + + it('should return true if grid has lazyLoad and node does not override', () => { + const node: any = { grid: { opts: { lazyLoad: true } } }; + expect(Utils.lazyLoad(node)).toBe(true); + }); + + it('should return false if node explicitly disables lazyLoad', () => { + const node: any = { lazyLoad: false, grid: { opts: { lazyLoad: true } } }; + expect(Utils.lazyLoad(node)).toBe(false); + }); + + it('should return false if no lazyLoad settings', () => { + const node: any = { grid: { opts: {} } }; + expect(Utils.lazyLoad(node)).toBeFalsy(); + }); + }); + + describe('createDiv', () => { + it('should create div with classes', () => { + const div = Utils.createDiv(['class1', 'class2']); + expect(div.tagName).toBe('DIV'); + expect(div.classList.contains('class1')).toBe(true); + expect(div.classList.contains('class2')).toBe(true); + }); + + it('should create div and append to parent', () => { + const parent = document.createElement('div'); + const div = Utils.createDiv(['test-class'], parent); + expect(parent.children.length).toBe(1); + expect(parent.children[0]).toBe(div); + }); + + it('should skip empty class names', () => { + const div = Utils.createDiv(['class1', '', 'class2']); + expect(div.classList.contains('class1')).toBe(true); + expect(div.classList.contains('class2')).toBe(true); + expect(div.classList.length).toBe(2); + }); + }); + + describe('shouldSizeToContent', () => { + it('should return true when node has sizeToContent true', () => { + const node: any = { grid: {}, sizeToContent: true }; + expect(Utils.shouldSizeToContent(node)).toBe(true); + }); + + it('should return true when grid has sizeToContent and node does not override', () => { + const node: any = { grid: { opts: { sizeToContent: true } } }; + expect(Utils.shouldSizeToContent(node)).toBe(true); + }); + + it('should return false when node explicitly disables sizeToContent', () => { + const node: any = { grid: { opts: { sizeToContent: true } }, sizeToContent: false }; + expect(Utils.shouldSizeToContent(node)).toBe(false); + }); + + it('should return true for numeric sizeToContent', () => { + const node: any = { grid: {}, sizeToContent: 5 }; + expect(Utils.shouldSizeToContent(node)).toBe(true); + }); + + it('should return false for numeric sizeToContent in strict mode', () => { + const node: any = { grid: { opts: {} }, sizeToContent: 5 }; + expect(Utils.shouldSizeToContent(node, true)).toBe(false); + }); + + it('should return true for boolean true in strict mode', () => { + const node: any = { grid: {}, sizeToContent: true }; + expect(Utils.shouldSizeToContent(node, true)).toBe(true); + }); + + it('should return false when no grid', () => { + const node: any = { sizeToContent: true }; + expect(Utils.shouldSizeToContent(node)).toBeFalsy(); + }); + }); + + describe('isTouching', () => { + it('should return true for touching rectangles', () => { + const a = { x: 0, y: 0, w: 2, h: 2 }; + const b = { x: 2, y: 0, w: 2, h: 2 }; + expect(Utils.isTouching(a, b)).toBe(true); + }); + + it('should return true for corner touching', () => { + const a = { x: 0, y: 0, w: 2, h: 2 }; + const b = { x: 2, y: 2, w: 2, h: 2 }; + expect(Utils.isTouching(a, b)).toBe(true); + }); + + it('should return false for non-touching rectangles', () => { + const a = { x: 0, y: 0, w: 2, h: 2 }; + const b = { x: 3, y: 3, w: 2, h: 2 }; + expect(Utils.isTouching(a, b)).toBe(false); + }); + }); + + describe('areaIntercept and area', () => { + it('should calculate overlapping area', () => { + const a = { x: 0, y: 0, w: 3, h: 3 }; + const b = { x: 1, y: 1, w: 3, h: 3 }; + expect(Utils.areaIntercept(a, b)).toBe(4); // 2x2 overlap + }); + + it('should return 0 for non-overlapping rectangles', () => { + const a = { x: 0, y: 0, w: 2, h: 2 }; + const b = { x: 3, y: 3, w: 2, h: 2 }; + expect(Utils.areaIntercept(a, b)).toBe(0); + }); + + it('should calculate total area', () => { + const rect = { x: 0, y: 0, w: 3, h: 4 }; + expect(Utils.area(rect)).toBe(12); + }); + }); + + describe('sort', () => { + it('should sort nodes by position ascending', () => { + const nodes: any = [ + { x: 2, y: 1 }, + { x: 1, y: 0 }, + { x: 0, y: 1 } + ]; + const sorted = Utils.sort(nodes); + expect(sorted[0].x).toBe(1); // y:0, x:1 + expect(sorted[1].x).toBe(0); // y:1, x:0 + expect(sorted[2].x).toBe(2); // y:1, x:2 + }); + + it('should sort nodes by position descending', () => { + const nodes: any = [ + { x: 1, y: 0 }, + { x: 0, y: 1 }, + { x: 2, y: 1 } + ]; + const sorted = Utils.sort(nodes, -1); + expect(sorted[0].x).toBe(2); // y:1, x:2 + expect(sorted[1].x).toBe(0); // y:1, x:0 + expect(sorted[2].x).toBe(1); // y:0, x:1 + }); + + it('should handle undefined coordinates', () => { + const nodes: any = [ + { x: 1 }, + { y: 1 }, + { x: 0, y: 0 } + ]; + const sorted = Utils.sort(nodes); + expect(sorted[0].x).toBe(0); // defined coordinates come first + }); + }); + + describe('find', () => { + it('should find node by id', () => { + const nodes: any = [ + { id: 'node1', x: 0 }, + { id: 'node2', x: 1 }, + { id: 'node3', x: 2 } + ]; + const found = Utils.find(nodes, 'node2'); + expect(found.x).toBe(1); + }); + + it('should return undefined for non-existent id', () => { + const nodes: any = [{ id: 'node1' }]; + const found = Utils.find(nodes, 'node2'); + expect(found).toBeUndefined(); + }); + + it('should return undefined for empty id', () => { + const nodes: any = [{ id: 'node1' }]; + const found = Utils.find(nodes, ''); + expect(found).toBeUndefined(); + }); + }); + + describe('toNumber', () => { + it('should convert string to number', () => { + expect(Utils.toNumber('42')).toBe(42); + expect(Utils.toNumber('3.14')).toBe(3.14); + }); + + it('should return undefined for null', () => { + expect(Utils.toNumber(null)).toBeUndefined(); + }); + + it('should return undefined for empty string', () => { + expect(Utils.toNumber('')).toBeUndefined(); + }); + }); + + describe('same', () => { + it('should return true for primitive equality', () => { + expect(Utils.same(5, 5)).toBe(true); + expect(Utils.same('test', 'test')).toBe(true); + expect(Utils.same(true, true)).toBe(true); + }); + + it('should return false for primitive inequality', () => { + expect(Utils.same(5, 6)).toBe(false); + expect(Utils.same('test', 'other')).toBe(false); + }); + + it('should return true for objects with same properties', () => { + expect(Utils.same({ a: 1, b: 2 }, { a: 1, b: 2 })).toBe(true); + }); + + it('should return false for objects with different properties', () => { + expect(Utils.same({ a: 1, b: 2 }, { a: 1, b: 3 })).toBe(false); + }); + + it('should return false for objects with different number of properties', () => { + expect(Utils.same({ a: 1 }, { a: 1, b: 2 })).toBe(false); + }); + + it('should return false for different types', () => { + expect(Utils.same(5, '5')).toBe(true); // same uses == comparison for primitives + expect(Utils.same({}, [])).toBe(true); // both are objects, same number of keys (0) + }); + }); + + describe('copyPos', () => { + it('should copy position properties', () => { + const target: any = {}; + const source: any = { x: 1, y: 2, w: 3, h: 4 }; + const result = Utils.copyPos(target, source); + + expect(result).toBe(target); + expect(target.x).toBe(1); + expect(target.y).toBe(2); + expect(target.w).toBe(3); + expect(target.h).toBe(4); + }); + + it('should copy min/max constraints when requested', () => { + const target: any = {}; + const source: any = { minW: 1, minH: 2, maxW: 10, maxH: 20 }; + Utils.copyPos(target, source, true); + + expect(target.minW).toBe(1); + expect(target.minH).toBe(2); + expect(target.maxW).toBe(10); + expect(target.maxH).toBe(20); + }); + + it('should not copy undefined properties', () => { + const target: any = { x: 5 }; + const source: any = { y: 2 }; + Utils.copyPos(target, source); + + expect(target.x).toBe(5); // unchanged + expect(target.y).toBe(2); + }); + }); + + describe('samePos', () => { + it('should return true for same positions', () => { + const a = { x: 1, y: 2, w: 3, h: 4 }; + const b = { x: 1, y: 2, w: 3, h: 4 }; + expect(Utils.samePos(a, b)).toBe(true); + }); + + it('should return false for different positions', () => { + const a = { x: 1, y: 2, w: 3, h: 4 }; + const b = { x: 1, y: 2, w: 3, h: 5 }; + expect(Utils.samePos(a, b)).toBe(false); + }); + + it('should handle default width/height of 1', () => { + const a = { x: 1, y: 2 }; + const b = { x: 1, y: 2, w: 1, h: 1 }; + expect(Utils.samePos(a, b)).toBe(true); + }); + + it('should return false for null/undefined', () => { + expect(Utils.samePos(null, { x: 1, y: 2 })).toBeFalsy(); + expect(Utils.samePos({ x: 1, y: 2 }, null)).toBeFalsy(); + }); + }); + + describe('sanitizeMinMax', () => { + it('should remove falsy min/max values', () => { + const node: any = { minW: 0, minH: null, maxW: undefined, maxH: 5 }; + Utils.sanitizeMinMax(node); + + expect(node.minW).toBeUndefined(); + expect(node.minH).toBeUndefined(); + expect(node.maxW).toBeUndefined(); + expect(node.maxH).toBe(5); + }); + }); + + describe('removeInternalForSave', () => { + it('should remove internal fields and defaults', () => { + const node: any = { + _internal: 'value', + grid: {}, + el: document.createElement('div'), + autoPosition: false, + noResize: false, + noMove: false, + locked: false, + w: 1, + h: 1, + x: 5, + y: 3 + }; + Utils.removeInternalForSave(node); + + expect(node._internal).toBeUndefined(); + expect(node.grid).toBeUndefined(); + expect(node.el).toBeUndefined(); + expect(node.autoPosition).toBeUndefined(); + expect(node.noResize).toBeUndefined(); + expect(node.noMove).toBeUndefined(); + expect(node.locked).toBeUndefined(); + expect(node.w).toBeUndefined(); + expect(node.h).toBeUndefined(); + expect(node.x).toBe(5); + expect(node.y).toBe(3); + }); + + it('should keep el when removeEl is false', () => { + const el = document.createElement('div'); + const node: any = { el }; + Utils.removeInternalForSave(node, false); + + expect(node.el).toBe(el); + }); + }); + + describe('throttle', () => { + it('should throttle function calls', async () => { + let callCount = 0; + const throttled = Utils.throttle(() => callCount++, 50); + + throttled(); + throttled(); + throttled(); + + expect(callCount).toBe(0); + + await new Promise(resolve => setTimeout(resolve, 60)); + expect(callCount).toBe(1); + }); + }); + + describe('cloneNode', () => { + it('should clone HTML element and remove id', () => { + const original = document.createElement('div'); + original.id = 'original-id'; + original.className = 'test-class'; + original.innerHTML = 'content'; + + const cloned = Utils.cloneNode(original); + + expect(cloned.id).toBe(''); + expect(cloned.className).toBe('test-class'); + expect(cloned.innerHTML).toBe('content'); + expect(cloned).not.toBe(original); + }); + }); + + describe('appendTo', () => { + it('should append element to parent by selector', () => { + document.body.innerHTML = '
'; + const child = document.createElement('div'); + + Utils.appendTo(child, '#parent'); + + const parent = document.getElementById('parent'); + expect(parent.children[0]).toBe(child); + }); + + it('should append element to parent element', () => { + const parent = document.createElement('div'); + const child = document.createElement('div'); + + Utils.appendTo(child, parent); + + expect(parent.children[0]).toBe(child); + }); + + it('should handle non-existent parent gracefully', () => { + const child = document.createElement('div'); + + expect(() => Utils.appendTo(child, '#non-existent')).not.toThrow(); + }); + }); + + describe('addElStyles', () => { + it('should add styles to element', () => { + const el = document.createElement('div'); + const styles = { + width: '100px', + height: '200px', + color: 'red' + }; + + Utils.addElStyles(el, styles); + + expect(el.style.width).toBe('100px'); + expect(el.style.height).toBe('200px'); + expect(el.style.color).toBe('red'); + }); + + it('should handle array styles (fallback values)', () => { + const el = document.createElement('div'); + const styles = { + display: ['-webkit-flex', 'flex'] + }; + + Utils.addElStyles(el, styles); + + expect(el.style.display).toBe('flex'); + }); + }); + + describe('initEvent', () => { + it('should create event object with properties', () => { + const originalEvent = new MouseEvent('mousedown', { + clientX: 100, + clientY: 200, + altKey: true + }); + + const newEvent = Utils.initEvent(originalEvent, { type: 'customEvent' }); + + expect(newEvent.type).toBe('customEvent'); + expect(newEvent.clientX).toBe(100); + expect(newEvent.clientY).toBe(200); + expect(newEvent.altKey).toBe(true); + expect(newEvent.button).toBe(0); + expect(newEvent.buttons).toBe(1); + }); + }); + + describe('simulateMouseEvent', () => { + it('should handle Touch object', () => { + const target = document.createElement('div'); + + // Test with simplified Touch-like object + const touchObj = { + screenX: 100, + screenY: 200, + clientX: 100, + clientY: 200, + target: target + }; + + // Just test that it tries to create an event + // The actual MouseEvent construction is tested at runtime + expect(typeof Utils.simulateMouseEvent).toBe('function'); + }); + }); + + describe('getValuesFromTransformedElement', () => { + it('should get transform values from parent', () => { + const parent = document.createElement('div'); + document.body.appendChild(parent); + + const result = Utils.getValuesFromTransformedElement(parent); + + expect(result.xScale).toBeDefined(); + expect(result.yScale).toBeDefined(); + expect(result.xOffset).toBeDefined(); + expect(result.yOffset).toBeDefined(); + + document.body.removeChild(parent); + }); + }); + + describe('swap', () => { + it('should swap object properties', () => { + const obj: any = { a: 'first', b: 'second' }; + + Utils.swap(obj, 'a', 'b'); + + expect(obj.a).toBe('second'); + expect(obj.b).toBe('first'); + }); + + it('should handle null object gracefully', () => { + expect(() => Utils.swap(null, 'a', 'b')).not.toThrow(); + }); + }); + + describe('canBeRotated', () => { + it('should return true for rotatable node', () => { + const node: any = { w: 2, h: 3, grid: { opts: {} } }; + expect(Utils.canBeRotated(node)).toBe(true); + }); + + it('should return false for square node', () => { + const node: any = { w: 2, h: 2 }; + expect(Utils.canBeRotated(node)).toBe(false); + }); + + it('should return false for locked node', () => { + const node: any = { w: 2, h: 3, locked: true }; + expect(Utils.canBeRotated(node)).toBe(false); + }); + + it('should return false for no-resize node', () => { + const node: any = { w: 2, h: 3, noResize: true }; + expect(Utils.canBeRotated(node)).toBe(false); + }); + + it('should return false when grid disables resize', () => { + const node: any = { w: 2, h: 3, grid: { opts: { disableResize: true } } }; + expect(Utils.canBeRotated(node)).toBe(false); + }); + + it('should return false for constrained width', () => { + const node: any = { w: 2, h: 3, minW: 2, maxW: 2 }; + expect(Utils.canBeRotated(node)).toBe(false); + }); + + it('should return false for constrained height', () => { + const node: any = { w: 2, h: 3, minH: 3, maxH: 3 }; + expect(Utils.canBeRotated(node)).toBe(false); + }); + + it('should return false for null node', () => { + expect(Utils.canBeRotated(null)).toBe(false); + }); + }); + + describe('parseHeight edge cases', () => { + it('should handle auto and empty string', () => { + expect(Utils.parseHeight('auto')).toEqual({ h: 0, unit: 'px' }); + expect(Utils.parseHeight('')).toEqual({ h: 0, unit: 'px' }); + }); + }); + + describe('updateScrollPosition', () => { + it('should update scroll position', () => { + const container = document.createElement('div'); + container.style.overflow = 'auto'; + container.style.height = '100px'; + document.body.appendChild(container); + + const el = document.createElement('div'); + container.appendChild(el); + + const position = { top: 50 }; + Utils.updateScrollPosition(el, position, 10); + + // Test that it doesn't throw and position is a number + expect(typeof position.top).toBe('number'); + + document.body.removeChild(container); + }); + }); + + describe('updateScrollResize', () => { + it('should handle scroll resize events', () => { + // Test that the function exists and can be called + expect(typeof Utils.updateScrollResize).toBe('function'); + + // Simple test to avoid jsdom scrollBy issues + const el = document.createElement('div'); + const mockEvent = { clientY: 50 } as MouseEvent; + + // The function implementation involves DOM scrolling which is complex in jsdom + // We just verify it's callable without extensive mocking + try { + Utils.updateScrollResize(mockEvent, el, 20); + } catch (e) { + // Expected in test environment due to scrollBy not being available + expect(e.message).toContain('scrollBy'); + } + }); + }); }); diff --git a/src/gridstack.ts b/src/gridstack.ts index 8401f434d..842e4ec80 100644 --- a/src/gridstack.ts +++ b/src/gridstack.ts @@ -6,7 +6,7 @@ * see root license https://github.com/gridstack/gridstack.js/tree/master/LICENSE */ import { GridStackEngine } from './gridstack-engine'; -import { Utils, HeightData, obsolete, DragTransform } from './utils'; +import { Utils, HeightData, DragTransform } from './utils'; import { gridDefaults, ColumnOptions, GridItemHTMLElement, GridStackElement, GridStackEventHandlerCallback, GridStackNode, GridStackWidget, numberOrString, DDUIData, DDDragOpt, GridStackPosition, GridStackOptions, @@ -950,12 +950,14 @@ export class GridStack { public cellWidth(): number { return this._widthOrContainer() / this.getColumn(); } + /** return our expected width (or parent) , and optionally of window for dynamic column check */ protected _widthOrContainer(forBreakpoint = false): number { // use `offsetWidth` or `clientWidth` (no scrollbar) ? // https://stackoverflow.com/questions/21064101/understanding-offsetwidth-clientwidth-scrollwidth-and-height-respectively return forBreakpoint && this.opts.columnOpts?.breakpointForWindow ? window.innerWidth : (this.el.clientWidth || this.el.parentElement.clientWidth || window.innerWidth); } + /** checks for dynamic column count for our current size, returning true if changed */ protected checkDynamicColumn(): boolean { const resp = this.opts.columnOpts; @@ -1799,17 +1801,7 @@ export class GridStack { * alert('Not enough free space to place the widget'); * } */ - public willItFit(node: GridStackWidget): boolean { - // support legacy call for now - if (arguments.length > 1) { - console.warn('gridstack.ts: `willItFit(x,y,w,h,autoPosition)` is deprecated. Use `willItFit({x, y,...})`. It will be removed soon'); - // eslint-disable-next-line prefer-rest-params - const a = arguments; let i = 0, - w: GridStackWidget = { x: a[i++], y: a[i++], w: a[i++], h: a[i++], autoPosition: a[i++] }; - return this.willItFit(w); - } - return this.engine.willItFit(node); - } + public willItFit(node: GridStackWidget): boolean { return this.engine.willItFit(node) } /** @internal */ protected _triggerChangeEvent(): GridStack { @@ -3015,7 +3007,4 @@ export class GridStack { this.engine.restoreInitial(); } } - - // legacy method removed - public commit(): GridStack { obsolete(this, this.batchUpdate(false), 'commit', 'batchUpdate', '5.2'); return this; } } diff --git a/src/utils.ts b/src/utils.ts index 024dbafd2..2969e4810 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -29,15 +29,15 @@ export interface DragTransform { * @returns a wrapper function that warns about deprecation */ // eslint-disable-next-line -export function obsolete(self, f, oldName: string, newName: string, rev: string): (...args: any[]) => any { - const wrapper = (...args) => { - console.warn('gridstack.js: Function `' + oldName + '` is deprecated in ' + rev + ' and has been replaced ' + - 'with `' + newName + '`. It will be **removed** in a future release'); - return f.apply(self, args); - } - wrapper.prototype = f.prototype; - return wrapper; -} +// export function obsolete(self, f, oldName: string, newName: string, rev: string): (...args: any[]) => any { +// const wrapper = (...args) => { +// console.warn('gridstack.js: Function `' + oldName + '` is deprecated in ' + rev + ' and has been replaced ' + +// 'with `' + newName + '`. It will be **removed** in a future release'); +// return f.apply(self, args); +// } +// wrapper.prototype = f.prototype; +// return wrapper; +// } /** * @internal Checks for obsolete grid options and migrates them to new names. @@ -48,13 +48,13 @@ export function obsolete(self, f, oldName: string, newName: string, rev: string) * @param newName the new option name to use instead * @param rev the version when the deprecation was introduced */ -export function obsoleteOpts(opts: GridStackOptions, oldName: string, newName: string, rev: string): void { - if (opts[oldName] !== undefined) { - opts[newName] = opts[oldName]; - console.warn('gridstack.js: Option `' + oldName + '` is deprecated in ' + rev + ' and has been replaced with `' + - newName + '`. It will be **removed** in a future release'); - } -} +// export function obsoleteOpts(opts: GridStackOptions, oldName: string, newName: string, rev: string): void { +// if (opts[oldName] !== undefined) { +// opts[newName] = opts[oldName]; +// console.warn('gridstack.js: Option `' + oldName + '` is deprecated in ' + rev + ' and has been replaced with `' + +// newName + '`. It will be **removed** in a future release'); +// } +// } /** * @internal Checks for obsolete grid options that have been completely removed. @@ -65,11 +65,11 @@ export function obsoleteOpts(opts: GridStackOptions, oldName: string, newName: s * @param rev the version when the option was removed * @param info additional information about the removal */ -export function obsoleteOptsDel(opts: GridStackOptions, oldName: string, rev: string, info: string): void { - if (opts[oldName] !== undefined) { - console.warn('gridstack.js: Option `' + oldName + '` is deprecated in ' + rev + info); - } -} +// export function obsoleteOptsDel(opts: GridStackOptions, oldName: string, rev: string, info: string): void { +// if (opts[oldName] !== undefined) { +// console.warn('gridstack.js: Option `' + oldName + '` is deprecated in ' + rev + info); +// } +// } /** * @internal Checks for obsolete HTML element attributes and migrates them. @@ -80,14 +80,14 @@ export function obsoleteOptsDel(opts: GridStackOptions, oldName: string, rev: st * @param newName the new attribute name to use instead * @param rev the version when the deprecation was introduced */ -export function obsoleteAttr(el: HTMLElement, oldName: string, newName: string, rev: string): void { - const oldAttr = el.getAttribute(oldName); - if (oldAttr !== null) { - el.setAttribute(newName, oldAttr); - console.warn('gridstack.js: attribute `' + oldName + '`=' + oldAttr + ' is deprecated on this object in ' + rev + ' and has been replaced with `' + - newName + '`. It will be **removed** in a future release'); - } -} +// export function obsoleteAttr(el: HTMLElement, oldName: string, newName: string, rev: string): void { +// const oldAttr = el.getAttribute(oldName); +// if (oldAttr !== null) { +// el.setAttribute(newName, oldAttr); +// console.warn('gridstack.js: attribute `' + oldName + '`=' + oldAttr + ' is deprecated on this object in ' + rev + ' and has been replaced with `' + +// newName + '`. It will be **removed** in a future release'); +// } +// } /** * Collection of utility methods used throughout GridStack.