Skip to content

Commit 2cecb25

Browse files
docs: standardize param and returns documentation across files
1 parent 57312dd commit 2cecb25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+527
-224
lines changed

browser/dom/_internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const encode = (
2525
* - `0`: returns `undefined`
2626
*
2727
* @param encoded The number containing encoded {@linkcode AddEventListenerOptions} flags
28-
* @returns An {@linkcode AddEventListenerOptions} object or `undefined` if encoded value is 0
28+
* @returns An {@linkcode AddEventListenerOptions} object or {@linkcode undefined} if encoded value is 0
2929
*/
3030
export const decode = (
3131
encoded: number,

browser/dom/cache.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* > Implementation inspired by Scrapbox's ServiceWorker and Cache usage pattern.
88
* > For details, see the article "ServiceWorker and Cache Usage in Scrapbox" {@see https://scrapbox.io/daiiz/ScrapboxでのServiceWorkerとCacheの活用#5d2efaffadf4e70000651173}
99
*
10-
* @param request The request to find a cached response for
11-
* @param options Cache query options (e.g., to ignore search params)
12-
* @return The cached response if found, otherwise `undefined`
10+
* @param request - The {@linkcode Request} to find a cached response for
11+
* @param options - {@linkcode CacheQueryOptions} (e.g., to ignore search params)
12+
* @returns A {@linkcode Response} if found, otherwise {@linkcode undefined}
1313
*/
1414
export const findLatestCache = async (
1515
request: Request,
@@ -26,8 +26,8 @@ export const findLatestCache = async (
2626

2727
/** Saves a response to the REST API cache storage managed by scrapbox.io
2828
*
29-
* @param request The request to associate with the cached response
30-
* @param response The response to cache
29+
* @param request The {@linkcode Request} to associate with the cached response
30+
* @param response The {@linkcode Response} to cache
3131
*/
3232
export const saveApiCache = async (
3333
request: Request,

browser/dom/caret.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ interface ReactFiber {
3939

4040
/** Retrieves the current cursor position and text selection information
4141
*
42-
* @return Information about cursor position and text selection
43-
* @throws {Error} When `#text-input` element or React Component's internal properties are not found
42+
* @returns A {@linkcode CaretPosition} containing cursor position and text selection information
43+
* @throws {@linkcode Error} when:
44+
* - `#text-input` element is not found
45+
* - React Component's internal properties are not found
4446
* @see {@linkcode CaretInfo} for return type details
4547
*/
4648
export const caret = (): CaretInfo => {

browser/dom/cursor.d.ts

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1+
/** @module cursor */
12
import { type BaseLine, BaseStore } from "@cosense/types/userscript";
23
import type { Position } from "./position.ts";
34
import type { Page } from "./page.d.ts";
45

6+
/** Options for setting cursor position
7+
* @interface
8+
*/
59
export interface SetPositionOptions {
610
/** Whether to auto-scroll the page when the cursor moves outside the viewport
711
*
812
* @default true
13+
* @type {boolean}
914
*/
1015
scrollInView?: boolean;
1116

1217
/** Source of the cursor movement event
1318
*
1419
* `"mouse"` indicates the cursor was moved by mouse interaction
20+
* @type {"mouse"}
1521
*/
1622
source?: "mouse";
1723
}
@@ -20,6 +26,7 @@ export interface SetPositionOptions {
2026
*
2127
* @see {@linkcode Position} for cursor position type details
2228
* @see {@linkcode Page} for page data type details
29+
* @extends {@linkcode BaseStore}<{ source: "mouse" | undefined } | "focusTextInput" | "scroll" | undefined>
2330
*/
2431
export declare class Cursor extends BaseStore<
2532
{ source: "mouse" | undefined } | "focusTextInput" | "scroll" | undefined
@@ -31,13 +38,24 @@ export declare class Cursor extends BaseStore<
3138
/** Reset cursor position and remove cursor focus from the editor */
3239
clear(): void;
3340

34-
/** Get the current cursor position */
41+
/** Get the current cursor position
42+
* @returns A {@linkcode Position} containing:
43+
* - Success: The current cursor coordinates and line information
44+
* - Error: Never throws or returns an error
45+
*/
3546
getPosition(): Position;
3647

37-
/** Check if the cursor is currently visible */
48+
/** Check if the cursor is currently visible
49+
* @returns A {@linkcode boolean} indicating:
50+
* - Success: `true` if the cursor is visible, `false` otherwise
51+
* - Error: Never throws or returns an error
52+
*/
3853
getVisible(): boolean;
3954

40-
/** Move the cursor to the specified position */
55+
/** Move the cursor to the specified position
56+
* @param position - The target position to move the cursor to
57+
* @param option - Optional settings for the cursor movement. See {@linkcode SetPositionOptions}
58+
*/
4159
setPosition(
4260
position: Position,
4361
option?: SetPositionOptions,
@@ -67,10 +85,18 @@ export declare class Cursor extends BaseStore<
6785
/** Adjust cursor position to stay within valid line and column boundaries */
6886
fixPosition(): void;
6987

70-
/** Returns `true` if the cursor is visible and at the start of a line */
88+
/** Check if the cursor is at the start of a line
89+
* @returns A {@linkcode boolean} indicating:
90+
* - Success: `true` if the cursor is visible and at line start, `false` otherwise
91+
* - Error: Never throws or returns an error
92+
*/
7193
isAtLineHead(): boolean;
7294

73-
/** Returns `true` if the cursor is visible and at the end of a line */
95+
/** Check if the cursor is at the end of a line
96+
* @returns A {@linkcode boolean} indicating:
97+
* - Success: `true` if the cursor is visible and at line end, `false` otherwise
98+
* - Error: Never throws or returns an error
99+
*/
74100
isAtLineTail(): boolean;
75101

76102
/** Make the cursor visible
@@ -87,6 +113,7 @@ export declare class Cursor extends BaseStore<
87113

88114
/** Cursor movement commands
89115
*
116+
* @param action - The movement command to execute. Available commands:
90117
* | Command | Description |
91118
* | ------ | ----------- |
92119
* | go-up | Move cursor up one line |
@@ -122,10 +149,18 @@ export declare class Cursor extends BaseStore<
122149
| "go-pageup",
123150
): void;
124151

125-
/** Get the content of the current page */
152+
/** Get the content of the current page
153+
* @returns An array of {@linkcode BaseLine} objects containing:
154+
* - Success: The current page's content as an array of line objects
155+
* - Error: Never throws or returns an error
156+
*/
126157
get lines(): BaseLine[];
127158

128-
/** Get the current page data */
159+
/** Get the current page data
160+
* @returns A {@linkcode Page} object containing:
161+
* - Success: The current page's metadata and content
162+
* - Error: Never throws or returns an error
163+
*/
129164
get page(): Page;
130165

131166
private goUp(): void;
@@ -134,7 +169,16 @@ export declare class Cursor extends BaseStore<
134169
private goPageDown(): void;
135170
private getNextLineHead(): void;
136171
private getPrevLineTail(): void;
172+
/** Move cursor backward one character
173+
* @param init - Optional configuration object
174+
* @param init.scrollInView - Whether to scroll the view to keep cursor visible
175+
*/
137176
private goBackward(init?: { scrollInView: boolean }): void;
177+
178+
/** Move cursor forward one character
179+
* @param init - Optional configuration object
180+
* @param init.scrollInView - Whether to scroll the view to keep cursor visible
181+
*/
138182
private goForward(init?: { scrollInView: boolean }): void;
139183
private goLeft(): void;
140184
private goRight(): void;
@@ -143,8 +187,18 @@ export declare class Cursor extends BaseStore<
143187
/** Jump to the end of the last line */
144188
private goBottom(): void;
145189
private goWordHead(): void;
190+
/** Get the position of the next word's start
191+
* @returns A {@linkcode Position} containing:
192+
* - Success: The coordinates and line information of the next word's start
193+
* - Error: Never throws or returns an error
194+
*/
146195
private getWordHead(): Position;
147196
private goWordTail(): void;
197+
/** Get the position of the previous word's end
198+
* @returns A {@linkcode Position} containing:
199+
* - Success: The coordinates and line information of the previous word's end
200+
* - Error: Never throws or returns an error
201+
*/
148202
private getWordTail(): Position;
149203
/** Jump to the position after indentation
150204
*

browser/dom/extractCodeFiles.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ export interface CodeBlock {
3737

3838
/** Extract code blocks from {@linkcode scrapbox.Page.lines}
3939
*
40-
* @param lines Page lines to process
41-
* @return A Map of source code files with filename as key
40+
* @param lines - Page lines to process
41+
* @returns A {@linkcode Map}<{@linkcode string}, {@linkcode string}> containing:
42+
* - Key: The filename
43+
* - Value: The source code content
4244
*/
4345
export const extractCodeFiles = (
4446
lines: Iterable<Line>,

browser/dom/motion.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { range } from "../../range.ts";
1919
*
2020
* This function is specifically for mobile version of Scrapbox
2121
*
22-
* @param [holding=1000] Duration of long press in milliseconds
22+
* @param [holding=1000] - Duration of long press in milliseconds
2323
*/
2424
export const focusEnd = async (holding = 1000): Promise<void> => {
2525
const target = getLineDOM(caret().position.line)
@@ -35,7 +35,7 @@ export const focusEnd = async (holding = 1000): Promise<void> => {
3535

3636
/** Move the cursor left using `ArrowLeft` key
3737
*
38-
* @param [count=1] Number of moves to perform
38+
* @param [count=1] - Number of moves to perform
3939
*/
4040
export const moveLeft = (count = 1): void => {
4141
for (const _ of range(0, count)) {
@@ -44,7 +44,7 @@ export const moveLeft = (count = 1): void => {
4444
};
4545
/** Move the cursor up using `ArrowUp` key
4646
*
47-
* @param [count=1] Number of moves to perform
47+
* @param [count=1] - Number of moves to perform
4848
*/
4949
export const moveUp = (count = 1): void => {
5050
for (const _ of range(0, count)) {
@@ -53,7 +53,7 @@ export const moveUp = (count = 1): void => {
5353
};
5454
/** Move the cursor down using `ArrowDown` key
5555
*
56-
* @param [count=1] Number of moves to perform
56+
* @param [count=1] - Number of moves to perform
5757
*/
5858
export const moveDown = (count = 1): void => {
5959
for (const _ of range(0, count)) {
@@ -62,7 +62,7 @@ export const moveDown = (count = 1): void => {
6262
};
6363
/** Move the cursor right using `ArrowRight` key
6464
*
65-
* @param [count=1] Number of moves to perform
65+
* @param [count=1] - Number of moves to perform
6666
*/
6767
export const moveRight = (count = 1): void => {
6868
for (const _ of range(0, count)) {
@@ -109,7 +109,7 @@ export const goLastLine = async (): Promise<void> => {
109109
};
110110
/** Move to the end of a specified line
111111
*
112-
* @param value Target line number, line ID, or {@linkcode HTMLElement}
112+
* @param value - Target line number, line ID, or {@linkcode HTMLElement}
113113
*/
114114
export const goLine = async (
115115
value: string | number | HTMLElement | undefined,
@@ -129,8 +129,8 @@ const _goLine = async (target: HTMLDivElement | undefined) => {
129129
*
130130
* Note: This operation will fail if attempting to move to characters that cannot be clicked in the UI
131131
*
132-
* @param line Target line (can be line number, line ID, or line DOM element)
133-
* @param pos Character position (column) in the target line
132+
* @param line - Target line (can be line number, line ID, or line DOM element)
133+
* @param pos - Character position (column) in the target line
134134
*/
135135
export const goChar = async (
136136
line: string | number | HTMLElement,
@@ -162,7 +162,7 @@ const getVisibleLineCount = (): number => {
162162

163163
/** Scroll half a page up
164164
*
165-
* @param [count=1] Number of scroll operations to perform
165+
* @param [count=1] - Number of scroll operations to perform
166166
*/
167167
export const scrollHalfUp = async (count = 1): Promise<void> => {
168168
const lineNo = getLineNo(caret().position.line);
@@ -176,7 +176,7 @@ export const scrollHalfUp = async (count = 1): Promise<void> => {
176176
};
177177
/** Scroll half a page down
178178
*
179-
* @param [count=1] Number of scroll operations to perform
179+
* @param [count=1] - Number of scroll operations to perform
180180
*/
181181
export const scrollHalfDown = async (count = 1): Promise<void> => {
182182
const lineNo = getLineNo(caret().position.line);
@@ -190,7 +190,7 @@ export const scrollHalfDown = async (count = 1): Promise<void> => {
190190
};
191191
/** Scroll one page up using `PageUp` key
192192
*
193-
* @param [count=1] Number of scroll operations to perform
193+
* @param [count=1] - Number of scroll operations to perform
194194
*/
195195
export const scrollUp = (count = 1): void => {
196196
for (const _ of range(0, count)) {
@@ -199,7 +199,7 @@ export const scrollUp = (count = 1): void => {
199199
};
200200
/** Scroll one page down using `PageDown` key
201201
*
202-
* @param [count=1] Number of scroll operations to perform
202+
* @param [count=1] - Number of scroll operations to perform
203203
*/
204204
export const scrollDown = (count = 1): void => {
205205
for (const _ of range(0, count)) {

browser/dom/open.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface OpenOptions {
1717
* - `true`: open in a new tab
1818
* - `false`: open in the same tab
1919
*
20-
* @default {false}
20+
* @default false
2121
*/
2222
newTab?: boolean;
2323

@@ -33,9 +33,9 @@ export interface OpenOptions {
3333

3434
/** Open a page
3535
*
36-
* @param project Project name of the page to open
37-
* @param title Title of the page to open
38-
* @param options Configuration options for opening the page
36+
* @param project - Project name of the page to open
37+
* @param title - Title of the page to open
38+
* @param options - Configuration options for opening the page
3939
*/
4040
export const open = (
4141
project: string,
@@ -78,9 +78,9 @@ export const open = (
7878
*
7979
* The page will not be reloaded when opened
8080
*
81-
* @param project Project name of the page to open
82-
* @param title Title of the page to open
83-
* @param [body] Text to append to the page
81+
* @param project - Project name of the page to open
82+
* @param title - Title of the page to open
83+
* @param [body] - Text to append to the page
8484
*/
8585
export const openInTheSameTab = (
8686
project: string,

browser/dom/page.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface SetPositionOptions {
55
/** Whether to auto-scroll the page when the cursor moves outside the viewport
66
* When `true`, the page will automatically scroll to keep the cursor visible
77
*
8-
* @default {true}
8+
* @default true
99
*/
1010
scrollInView?: boolean;
1111

browser/dom/press.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface PressOptions {
1616
* > This function appears to block synchronously until Scrapbox's event listeners
1717
* finish processing the keyboard event.
1818
*
19-
* @param key The name of the key to simulate pressing
20-
* @param pressOptions Additional options for the key press (modifiers, etc.)
19+
* @param key - The name of the key to simulate pressing
20+
* @param pressOptions - Additional options for the key press (modifiers, etc.)
2121
*/
2222
export const press = (
2323
key: KeyName,

browser/dom/selection.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export declare class Selection extends BaseStore<undefined> {
2222
*
2323
* @param init Set `init.normalizeOrder` to `true` to ensure Range.start is
2424
* the beginning of the selection (useful for consistent text processing)
25-
* @return The current selection range
25+
* @returns The current {@linkcode Range} object representing the selection
2626
*/
2727
getRange(init?: { normalizeOrder: boolean }): Range;
2828

@@ -34,8 +34,8 @@ export declare class Selection extends BaseStore<undefined> {
3434

3535
/** Normalize the selection range order to ensure start position comes before end
3636
*
37-
* @param range The selection range to normalize
38-
* @return The normalized range with start position at the beginning
37+
* @param range - The selection range to normalize
38+
* @returns A normalized {@linkcode Range} with start position at the beginning
3939
*
4040
* This is useful when you need consistent text processing regardless of
4141
* whether the user selected text from top-to-bottom or bottom-to-top.

0 commit comments

Comments
 (0)