Skip to content

Commit 38f4526

Browse files
committed
:refactor: Change some type to interfaces
Add more JSDoc
1 parent 875d491 commit 38f4526

File tree

3 files changed

+73
-49
lines changed

3 files changed

+73
-49
lines changed

api/response.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,22 @@ export interface MemberProject extends Omit<NotMemberProject, "isMember"> {
105105
backuped: number | null;
106106
}
107107

108+
export interface GuestUser {
109+
isGuest: true;
110+
csrfToken: string;
111+
}
112+
113+
export interface MemberUser extends UserInfo {
114+
isGuest: false;
115+
csrfToken: string;
116+
config: {
117+
userScript: boolean;
118+
emacsBinding: boolean;
119+
};
120+
}
121+
108122
/** the response type of https://scrapbox.io/api/users/me */
109-
export type UserResponse =
110-
| {
111-
isGuest: true;
112-
csrfToken: string;
113-
}
114-
| ({
115-
isGuest: false;
116-
csrfToken: string;
117-
config: {
118-
userScript: boolean;
119-
emacsBinding: boolean;
120-
};
121-
} & UserInfo);
123+
export type UserResponse = GuestUser | MemberUser;
122124

123125
/** the response type of https://scrapbox.io/api/pages/:projectname/search/titles */
124126
export interface SearchedTitle {

userscript.ts

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,8 @@ export type Scrapbox =
3434
addSeparator: () => void;
3535
removeAllItems: () => void;
3636
};
37-
addListener: (type: string, listener: () => void) => void;
38-
on: (type: string, listener: () => void) => void;
39-
removeListener: (type: string, listener: () => void) => void;
40-
off: (type: string, listener: () => void) => void;
41-
removeAllListeners: (type?: string) => void;
42-
once: (type: string, listener: () => void) => void;
43-
prependListener: (type: string, listener: () => void) => void;
44-
prependOnceListener: (type: string, listener: () => void) => void;
45-
listeners: (type: string) => (() => void)[];
46-
rawListeners: (type: string) => (() => void)[];
47-
listenerCount: (type: string) => number;
48-
emit: (type: string) => void;
49-
eventNames: () => string[];
50-
getMexListeners: () => number;
51-
setMexListeners: (length: number) => void;
5237
}
38+
& UserScriptEvents
5339
& ({
5440
Layout:
5541
| "list"
@@ -74,6 +60,23 @@ export type Scrapbox =
7460
};
7561
});
7662

63+
export interface UserScriptEvents {
64+
addListener: (type: string, listener: () => void) => void;
65+
on: (type: string, listener: () => void) => void;
66+
removeListener: (type: string, listener: () => void) => void;
67+
off: (type: string, listener: () => void) => void;
68+
removeAllListeners: (type?: string) => void;
69+
once: (type: string, listener: () => void) => void;
70+
prependListener: (type: string, listener: () => void) => void;
71+
prependOnceListener: (type: string, listener: () => void) => void;
72+
listeners: (type: string) => (() => void)[];
73+
rawListeners: (type: string) => (() => void)[];
74+
listenerCount: (type: string) => number;
75+
emit: (type: string) => void;
76+
eventNames: () => string[];
77+
getMexListeners: () => number;
78+
setMexListeners: (length: number) => void;
79+
}
7780
export interface PageBrief {
7881
/** true when the page has contents */ exists: boolean;
7982
/** whether the page contains any image */ hasIcon?: boolean;
@@ -83,20 +86,35 @@ export interface PageBrief {
8386
/** updated time */ updated: number;
8487
}
8588

86-
type TimeStamp = {
89+
export interface TimeStamp {
90+
/** Add a timestamp format to Scrapbox
91+
*
92+
* @param format a format of timestamp. this follow the moment.js format. You can set a function which returns any string
93+
*/
8794
addFormat: (format: string | (() => string)) => void;
95+
/** Remove all timestamp formats from Scrapbox
96+
*
97+
* These include default formats
98+
*/
8899
removeAllFormat: () => void;
89-
};
100+
}
90101

91-
type AddItemProps = {
92-
title: string | (() => string);
102+
export interface AddItemProps {
103+
/** the title of a menu item */ title: string | (() => string);
104+
/** the URL of an image which views on the left of the title */
93105
image?: string;
106+
/** the event listener which is executed when the menu item is clicked */
94107
onClick: () => void;
95-
};
96-
type PageMenu = {
108+
}
109+
export interface PageMenu {
110+
/** Add a menu item to a particular Page Menu button
111+
*
112+
* @param props information used for a menu item
113+
*/
97114
addItem: (
98115
props: AddItemProps,
99116
) => void;
117+
/** Add a separator to a particular Page Menu button */
100118
addSeparator: () => void;
101119
removeAllItems: () => void;
102120
menuName: string;
@@ -110,7 +128,7 @@ type PageMenu = {
110128
items: (AddItemProps & { separator: boolean })[];
111129
}
112130
>;
113-
};
131+
}
114132

115133
/** built-in UserScript events */
116134
export type eventName =

userscript/blocks.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,24 @@ export type ParsedLine =
2929
nodes: Node[];
3030
});
3131

32-
export type CodeBlock = {
33-
lang: string;
34-
filename?: string;
35-
indent: number;
36-
start: boolean;
37-
end: boolean;
38-
};
39-
export type TableBlock = {
40-
title: string;
41-
cells: string[];
42-
indent: number;
43-
start: boolean;
44-
end: boolean;
45-
};
32+
/** the type which represents a line in a block */
33+
export interface Block {
34+
/** the number of indents */ indent: number;
35+
/** is the start line of this block */ start: boolean;
36+
/** is the end line of this block */ end: boolean;
37+
}
38+
39+
/** the type which represents a line in a code block */
40+
export interface CodeBlock extends Block {
41+
/** the language of the code block */ lang: string;
42+
/** the file name of the code block */ filename?: string;
43+
}
44+
45+
/** the type which represents a line in a table block */
46+
export interface TableBlock extends Block {
47+
/** the title of the table block */ title: string;
48+
/** cells included in the present line */ cells: string[];
49+
}
4650
export type Helpfeel = {
4751
prefix: "?";
4852
entry: string;

0 commit comments

Comments
 (0)