Skip to content

Commit 5b93084

Browse files
authored
Merge pull request #3300 from adumesny/master
partial code cleanup - future TODO list creation
2 parents 4daaebe + ac896f9 commit 5b93084

10 files changed

Lines changed: 150 additions & 216 deletions

File tree

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ module.exports = {
1616
},
1717
rules: {
1818
'indent': ['error', 2],
19-
'max-len': ['error', 180],
19+
'max-len': 0,
2020
'no-trailing-spaces': 1,
2121
'prefer-const': 0,
2222
'@typescript-eslint/ban-ts-comment': 0,
23-
'max-len': 0
23+
'@typescript-eslint/no-explicit-any': 'warn',
2424
}
2525
};

TODO.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Technical Debt / Future Work
2+
3+
Items deferred from the June 2026 code-quality pass. Tackle in order; each builds on the previous.
4+
5+
---
6+
7+
## 1. TypeScript strict mode migration
8+
9+
**Why:** `tsconfig.json` runs with `strict: false` and `noImplicitAny: false`, hiding a whole class of bugs from both the compiler and consumers who rely on the published `.d.ts` declarations.
10+
11+
**Steps:**
12+
1. Enable `"strictNullChecks": true` first (lowest noise). Fix the resulting errors — most are already nullable but were silently untyped.
13+
2. Enable `"noImplicitReturns": true` and `"noImplicitAny": true`. The majority of remaining issues will be in the drag-and-drop internals (`dd-draggable.ts`, `dd-resizable.ts`) and the engine.
14+
3. Finally set `"strict": true` to catch the rest (strict function types, strict property init, etc.).
15+
4. Remove the per-file `// eslint-disable-next-line @typescript-eslint/no-explicit-any` suppressions as each file is cleaned up.
16+
17+
**Estimated scope:** ~50-80 type errors once `strictNullChecks` is on, mostly in `gridstack.ts` and the DD layer.
18+
19+
---
20+
21+
## 2. Break up `gridstack.ts` (~3 100 lines)
22+
23+
**Why:** The single `GridStack` class has grown to cover CSS/cell-height management, responsive/column layout, drag-drop wiring, serialization, and the public API. This makes it hard to navigate and test in isolation.
24+
25+
**Proposed split:**
26+
27+
| New file | Responsibility |
28+
|---|---|
29+
| `gridstack-css.ts` | `cellHeight()`, `_initMargin()`, `_updateStyles()`, CSS variable management |
30+
| `gridstack-column.ts` | `column()`, `checkDynamicColumn()`, `_columnLayouts`, responsive breakpoint logic |
31+
| `gridstack-dnd.ts` | `_setupAcceptWidget()`, `_setupRemoveDrop()`, `_onStartMoving()`, `_onEndMoving()`, drag/resize event wiring |
32+
| `gridstack-serialize.ts` | `save()`, `load()`, `_readAttr()`, `_writePosAttr()` |
33+
| `gridstack.ts` | Public API surface + constructor, thin delegation to the above |
34+
35+
**Approach:** Use mixin-style imports or prototype extension (same pattern the DD layer already uses) so the public class shape is unchanged and no semver break occurs.
36+
37+
---
38+
39+
## 3. Build toolchain consolidation
40+
41+
**Why:** The build currently combines Grunt + webpack + `tsc`. The React/Vue demo apps already use Vite. Consolidating onto a single bundler would simplify CI, reduce dependency surface, and speed up the build.
42+
43+
**Proposed target:** Rollup (or Vite's library mode) for the core `src/` library, keeping the framework wrappers on their own build.
44+
45+
**Steps:**
46+
1. Audit `Gruntfile.js` — identify what it does beyond what `tsc` + webpack already cover (likely banners and legacy UMD output).
47+
2. Replace webpack config with a Rollup config producing ESM + CJS + UMD outputs (same as today).
48+
3. Remove `Gruntfile.js` and the `grunt` dependency once the Rollup outputs match.
49+
4. Update `package.json` `"build"` script.
50+
5. Verify the demo apps still work (`yarn build:ng`, `yarn build:react`).
51+
52+
---
53+
54+
## 4. Accessibility (ARIA) support
55+
56+
**Why:** Grid items are plain `<div>` elements with no ARIA roles or keyboard interaction, making the library unusable for accessibility-sensitive dashboards.
57+
58+
**Minimum viable work:**
59+
- Add `role="grid"` to the container and `role="gridcell"` (or `"group"`) to items.
60+
- Emit `aria-grabbed="true/false"` during drag.
61+
- Document how to layer keyboard-move support on top (arrow keys to move focused item, or provide an optional built-in mode).
62+
63+
---
64+
65+
## 5. `Utils.getValuesFromTransformedElement` — cache per drag session
66+
67+
**Why:** This method creates, appends, reads, and removes a probe `<div>` on every call to calculate CSS transform scale/offset. If called during drag/resize events it triggers repeated forced layout (reflow).
68+
69+
**Fix:** Cache the result on the grid element (or `dragTransform` property) and invalidate only when a `ResizeObserver` or transform change is detected, rather than recomputing each drag tick.

angular/projects/lib/src/lib/gridstack.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export class GridstackComponent implements OnInit, AfterContentInit, OnDestroy {
267267
public ngOnInit(): void {
268268
// init ourself before any template children are created since we track them below anyway - no need to double create+update widgets
269269
this.loaded = !!this.options?.children?.length;
270-
this._grid = GridStack.init(this._options, this.el);
270+
this._grid = GridStack.init(this._options, this.el)!;
271271
delete this._options; // GS has it now
272272

273273
this.checkEmpty();

0 commit comments

Comments
 (0)