Skip to content

Commit 659e6f6

Browse files
authored
Merge pull request #4 from takker99/feature/scrapbox-page-lines
Add types of `scrapbox.Page.lines`
2 parents 89d10c9 + 94cb30e commit 659e6f6

File tree

2 files changed

+260
-14
lines changed

2 files changed

+260
-14
lines changed

line.d.ts

Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
export type ParsedLine =
2+
& {
3+
text: string;
4+
id: string;
5+
userId: string;
6+
updated: number;
7+
created: number;
8+
section: {
9+
number: number;
10+
start: boolean;
11+
end: boolean;
12+
};
13+
}
14+
& ({
15+
title?: boolean;
16+
} | {
17+
codeBlock: CodeBlock;
18+
} | {
19+
tableBlock: TableBlock;
20+
} | {
21+
helpfeel: Helpfeel;
22+
} | {
23+
cli: Cli;
24+
} | {
25+
formulaLine?: true;
26+
nodes: NodeWithoutIndent[];
27+
} | {
28+
numberList?: { digit: number };
29+
formulaLine?: true;
30+
nodes: Node[];
31+
});
32+
33+
export type CodeBlock = {
34+
lang: string;
35+
filename?: string;
36+
indent: number;
37+
start: boolean;
38+
end: boolean;
39+
};
40+
export type TableBlock = {
41+
title: string;
42+
cells: string[];
43+
indent: number;
44+
start: boolean;
45+
end: boolean;
46+
};
47+
export type Helpfeel = {
48+
prefix: "?";
49+
entry: string;
50+
};
51+
export type Cli = {
52+
prefix: "$" | "%";
53+
command: string;
54+
};
55+
56+
type NodeBase =
57+
| PlainText
58+
| Blank
59+
| Video
60+
| Vimeo
61+
| Decoration
62+
| Link
63+
| Quote
64+
| Code
65+
| Audio
66+
| AudioLink
67+
| Image
68+
| StrongImage
69+
| Gyazo
70+
| StrongGyazo
71+
| ImageLink
72+
| StrongImageLink
73+
| GyazoLink
74+
| StrongGyazoLink
75+
| Strong
76+
| Icon
77+
| StrongIcon
78+
| Url
79+
| UrlLink
80+
| Youtube
81+
| GoogleMap;
82+
type NodeWithoutIndent = NodeBase | Formula;
83+
export type Node = NodeWithoutIndent | Indent;
84+
type UnitBase = {
85+
content: string;
86+
whole: string;
87+
};
88+
export type PlainText = string;
89+
export type Blank = {
90+
type: "blank";
91+
unit: UnitBase;
92+
children: PlainText;
93+
};
94+
export type Video = {
95+
type: "video";
96+
unit: UnitBase;
97+
fileId: string | undefined;
98+
children: PlainText;
99+
};
100+
export type Vimeo = {
101+
type: "vimeo";
102+
unit: UnitBase & {
103+
videoId: string;
104+
};
105+
children: PlainText;
106+
};
107+
export type Decoration = {
108+
type: "deco";
109+
unit: UnitBase & {
110+
deco: string;
111+
strong: number;
112+
italic: boolean;
113+
strike: boolean;
114+
underline: boolean;
115+
};
116+
children: NodeWithoutIndent;
117+
};
118+
export type Link = {
119+
type: "link";
120+
unit:
121+
& UnitBase
122+
& ({
123+
page: string;
124+
} | {
125+
project: string;
126+
page: string;
127+
} | {
128+
project: string;
129+
});
130+
children: PlainText;
131+
};
132+
export type Quote = {
133+
type: "quote";
134+
unit: UnitBase & {
135+
tag: string;
136+
};
137+
children: NodeWithoutIndent;
138+
};
139+
export type Code = {
140+
type: "code";
141+
unit: UnitBase;
142+
children: PlainText;
143+
};
144+
export type Indent = {
145+
type: "indent";
146+
unit: UnitBase & {
147+
tag: string;
148+
};
149+
children: NodeWithoutIndent;
150+
};
151+
export type Audio = {
152+
type: "audio";
153+
unit: UnitBase;
154+
fileId: string | undefined;
155+
children: PlainText;
156+
};
157+
export type AudioLink = {
158+
type: "audioLink";
159+
unit: UnitBase & {
160+
link: string;
161+
title: string;
162+
};
163+
fileId: string | undefined;
164+
children: PlainText;
165+
};
166+
export type Image = ImageBase & { type: "image" };
167+
export type StrongImage = ImageBase & { type: "strongImage" };
168+
type ImageBase = {
169+
unit: UnitBase;
170+
fileId: string | undefined;
171+
children: PlainText;
172+
};
173+
export type Gyazo = GyazoBase & { type: "gyazo" };
174+
export type StrongGyazo = GyazoBase & { type: "strongGyazo" };
175+
type GyazoBase = {
176+
unit: UnitBase;
177+
children: PlainText;
178+
};
179+
export type ImageLink = ImageLinkBase & { type: "imageLink" };
180+
export type StrongImageLink = ImageLinkBase & { type: "strongImageLink" };
181+
type ImageLinkBase = {
182+
unit: UnitBase & {
183+
image: string;
184+
link: string;
185+
};
186+
children: PlainText;
187+
};
188+
export type GyazoLink = GyazoLinkBase & { type: "gyazoLink" };
189+
export type StrongGyazoLink = GyazoLinkBase & { type: "strongGyazoLink" };
190+
type GyazoLinkBase = {
191+
unit: UnitBase & {
192+
gyazo: string;
193+
link: string;
194+
};
195+
children: PlainText;
196+
};
197+
export type Icon = IconBase & { type: "icon" };
198+
export type StrongIcon = IconBase & { type: "strong-icon" };
199+
type IconBase = {
200+
unit: UnitBase & {
201+
project?: string;
202+
page: string;
203+
size: number;
204+
};
205+
children: PlainText;
206+
};
207+
export type Formula = {
208+
type: "deco-formula";
209+
unit: UnitBase & {
210+
formula: string;
211+
};
212+
children: PlainText;
213+
};
214+
export type Strong = {
215+
type: "strong";
216+
unit: UnitBase;
217+
children: NodeWithoutIndent;
218+
};
219+
export type Url = {
220+
type: "url";
221+
unit: UnitBase;
222+
fileId: string | undefined;
223+
children: PlainText;
224+
};
225+
export type UrlLink = {
226+
type: "urlLink";
227+
unit: UnitBase & {
228+
link: string;
229+
title?: string;
230+
};
231+
fileId: string | undefined;
232+
children: PlainText;
233+
};
234+
export type Youtube = {
235+
type: "youtube";
236+
unit:
237+
& UnitBase
238+
& {
239+
params: Record<string, string> & { t?: number };
240+
}
241+
& ({
242+
videoId?: string;
243+
} | {
244+
listId?: string;
245+
});
246+
children: PlainText;
247+
};
248+
export type GoogleMap = {
249+
type: "location";
250+
unit: UnitBase & {
251+
latitude: number;
252+
longitude: number;
253+
zoom: number;
254+
title?: string;
255+
};
256+
children: PlainText;
257+
};

scrapbox.d.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import type { ParsedLine } from "./line.d.ts";
2+
export * from "./line.d.ts";
3+
14
// utilities
25
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
36

@@ -279,20 +282,6 @@ export type PageBrief = {
279282
updated: number;
280283
};
281284

282-
export type ParsedLine = {
283-
text: string;
284-
id: string;
285-
userId: string;
286-
updated: number;
287-
created: number;
288-
section: {
289-
number: number;
290-
start: boolean;
291-
end: boolean;
292-
};
293-
title?: boolean;
294-
};
295-
296285
type TimeStamp = {
297286
addFormat: (format: string | (() => string)) => void;
298287
removeAllFormat: () => void;

0 commit comments

Comments
 (0)