Skip to content

Commit 02f7030

Browse files
committed
[Refactor] *: align naming/convention, ironed out structure
1 parent 7bae3d5 commit 02f7030

15 files changed

Lines changed: 250 additions & 475 deletions

AGENTS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ make clean
3838
- Tab indentation, size 2 for HTML/XML
3939
- No semicolons required
4040
- Use `const` and `let`, avoid `var`
41+
- Prefer `function name(...) {}` for top-level functions
42+
- Use arrow functions for callbacks, closures, and inline lambdas
4143

4244
### Imports
4345
```javascript
@@ -77,7 +79,7 @@ Exports are consolidated at the end of each file, not inline.
7779

7880
```javascript
7981
// Named exports for utilities
80-
const query = (selector, scope, limit) => { ... }
82+
function query(selector, scope, limit) { ... }
8183
class Selection extends Array { ... }
8284

8385
// Default export (one per module)
@@ -158,6 +160,7 @@ export { {{name}} }
158160
- **Module-level docs**: Define concepts, keywords, and provide overview
159161
- **Type/Class docs**: Describe purpose; list attributes as bullet points with types
160162
- **Function/Method docs**: Embed parameters in description using backticks; include examples for factory functions and complex APIs
163+
- **Top-level functions**: Use `function name(...) {}` declarations instead of `const name = (...) =>` for exported and module-level APIs
161164
- **Exports**: Named exports listed at file end with explicit `// EOF` marker
162165
- **Examples**: Always use fenced code blocks with language specifier; comment style for examples matches the surrounding code
163166
- **Visibility**: Don't use private/protected, but group internal operations together with a SUBSECTION

plan-refactor.md

Lines changed: 0 additions & 209 deletions
This file was deleted.

src/js/select/cells.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ const log = logger("select.cells");
4747
//
4848
// ----------------------------------------------------------------------------
4949

50-
const normalizeSelectionPath = (path) =>
51-
path === undefined || path === null
50+
function normalizeSelectionPath(path) {
51+
return path === undefined || path === null
5252
? []
5353
: Array.isArray(path)
5454
? path
55-
: [path];
55+
: [path]
56+
}
5657

57-
const selectionPathKey = (path) => {
58+
function selectionPathKey(path) {
5859
if (!path || path.length === 0) {
5960
return "";
6061
}
@@ -66,7 +67,7 @@ const selectionPathKey = (path) => {
6667
key += `${typeof path[i]}:${path[i]}`;
6768
}
6869
return key;
69-
};
70+
}
7071

7172
// ----------------------------------------------------------------------------
7273
//

src/js/select/formats.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Project: Select.js
2+
// Author: Sebastien Pierre
3+
// License: MIT
4+
// Created: 2026-05-15
5+
6+
// Module: select/formats
7+
// String case format helpers shared across modules.
8+
9+
function toKebabCase(value) {
10+
return `${value}`
11+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
12+
.replace(/[_\s]+/g, "-")
13+
.toLowerCase()
14+
}
15+
16+
function toCamelCase(value) {
17+
return `${value}`
18+
.toLowerCase()
19+
.replace(/-([a-z0-9])/g, (_, letter) => letter.toUpperCase())
20+
}
21+
22+
export {
23+
toCamelCase,
24+
toKebabCase,
25+
}
26+
27+
// EOF

src/js/select/interaction.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Module: select/interaction
77
// DOM interaction helpers.
88

9-
const bind = (node, handlers) => {
9+
function bind(node, handlers) {
1010
if (handlers) {
1111
for (const [name, handler] of Object.entries(handlers)) {
1212
for (const target of Array.isArray(node) ? node : [node]) {
@@ -15,9 +15,9 @@ const bind = (node, handlers) => {
1515
}
1616
}
1717
return node;
18-
};
18+
}
1919

20-
const unbind = (node, handlers) => {
20+
function unbind(node, handlers) {
2121
if (handlers) {
2222
for (const [name, handler] of Object.entries(handlers)) {
2323
for (const target of Array.isArray(node) ? node : [node]) {
@@ -26,9 +26,9 @@ const unbind = (node, handlers) => {
2626
}
2727
}
2828
return node;
29-
};
29+
}
3030

31-
const drag = (event, move, end) => {
31+
function drag(event, move, end) {
3232
const context = {};
3333
const dragging = {
3434
node: event.target,
@@ -77,36 +77,36 @@ const drag = (event, move, end) => {
7777
const doEnd = () => unbind(scope, handlers);
7878
bind(scope, handlers);
7979
return doEnd;
80-
};
80+
}
8181

82-
const target = (node, pred) => {
82+
function target(node, pred) {
8383
while (node && node.nodeType === Node.ELEMENT_NODE) {
8484
if (pred(node)) return node;
8585
node = node.parentNode;
8686
}
8787
return undefined;
88-
};
88+
}
8989

90-
const dragtarget = (node, name) => {
90+
function dragtarget(node, name) {
9191
while (node && node.nodeType === Node.ELEMENT_NODE) {
9292
const element = node;
9393
if (!name && element.hasAttribute("data-drag")) return element;
9494
if (name && element.getAttribute("data-drag") === name) return element;
9595
node = element.parentNode;
9696
}
9797
return node?.nodeType === Node.ELEMENT_NODE ? node : undefined;
98-
};
98+
}
9999

100100
drag.target = dragtarget;
101101

102-
const autoresize = (event) => {
102+
function autoresize(event) {
103103
const node = event.target;
104104
node.style.height = "auto";
105105
const style = globalThis.window.getComputedStyle(node);
106106
const border =
107107
parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
108108
node.style.height = `${border + node.scrollHeight}px`;
109-
};
109+
}
110110

111111
const Keyboard = {
112112
Down: "keydown",

0 commit comments

Comments
 (0)