Skip to content

Commit 6e6ea0a

Browse files
committed
♻️ Cursorの型定義を厳密にした
1 parent 4a45854 commit 6e6ea0a

File tree

2 files changed

+83
-5
lines changed

2 files changed

+83
-5
lines changed

browser/dom/cursor.d.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
/// <reference lib="esnext"/>
33
/// <reference lib="dom" />
44

5-
import { BaseStore } from "../../deps/scrapbox.ts";
5+
import { BaseLine, BaseStore } from "../../deps/scrapbox.ts";
66
import { Position } from "./position.ts";
7+
import { Page } from "./page.d.ts";
78

89
export interface SetPositionOptions {
910
/** カーソルが画面外に移動したとき、カーソルが見える位置までページをスクロールするかどうか
@@ -25,6 +26,8 @@ export declare class Cursor extends BaseStore<
2526
> {
2627
constructor();
2728

29+
public startedWithTouch: boolean;
30+
2831
/** カーソルの位置を初期化し、editorからカーソルを外す */
2932
clear(): void;
3033

@@ -52,6 +55,12 @@ export declare class Cursor extends BaseStore<
5255
*/
5356
focus(): void;
5457

58+
/** #text-inputにfocusがあたっているか返す
59+
*
60+
* `this.focusTextarea`と同値
61+
*/
62+
get hasFocus(): boolean;
63+
5564
/** #text-inputからfocusを外す。カーソルの表示状態は変えない */
5665
blur(): void;
5766

@@ -113,11 +122,11 @@ export declare class Cursor extends BaseStore<
113122
| "go-pageup",
114123
): void;
115124

116-
/* `scrapbox.Page.lines`とほぼ同じ */
117-
get lines(): unknown[];
125+
/** 現在のページ本文を取得する */
126+
get lines(): BaseLine[];
118127

119-
/* `scrapbox.Project.pages`とほぼ同じ */
120-
get pages(): unknown;
128+
/** 現在のページデータを取得する */
129+
get page(): Page;
121130

122131
private goUp(): void;
123132
private goPageUp(): void;

browser/dom/page.d.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/// <reference no-default-lib="true"/>
2+
/// <reference lib="esnext"/>
3+
/// <reference lib="dom" />
4+
5+
import { BaseStore } from "../../deps/scrapbox.ts";
6+
import { Page as PageData } from "../../deps/scrapbox-rest.ts";
7+
8+
export interface SetPositionOptions {
9+
/** カーソルが画面外に移動したとき、カーソルが見える位置までページをスクロールするかどうか
10+
*
11+
* @default true
12+
*/
13+
scrollInView?: boolean;
14+
15+
/** カーソル移動イベントの発生箇所?
16+
*
17+
* コード内だと、"mouse"が指定されていた場合があった。詳細は不明
18+
*/
19+
source?: "mouse";
20+
}
21+
22+
export interface ApiUrlForFetch {
23+
projectName: string;
24+
title: string;
25+
titleHint: string;
26+
followRename: boolean;
27+
search: string;
28+
}
29+
30+
export interface ApplySnapshotInit {
31+
page: Pick<PageData, "title" | "lines" | "created">;
32+
prevPage?: Pick<PageData, "created">;
33+
nextPage?: Pick<PageData, "lines">;
34+
}
35+
36+
export type PageWithCache = PageData & { cachedAt: number | undefined };
37+
38+
/** Scrapboxのページデータを管理する内部クラス
39+
*
40+
* 一部型定義は書きかけ
41+
*/
42+
export declare class Page extends BaseStore<
43+
{ source: "mouse" | undefined } | "focusTextInput" | "scroll" | undefined
44+
> {
45+
public initialize(): void;
46+
47+
private data: PageWithCache;
48+
49+
public get(): PageWithCache;
50+
51+
public apiUrlForFetch(init: ApiUrlForFetch): string;
52+
public apiUrlForUpdatePageAccessed(pageId: string): string;
53+
public fetch(): Promise<PageWithCache>;
54+
55+
public set(page: PageWithCache): void;
56+
public reset(): void;
57+
public applySnapshot(init: ApplySnapshotInit): void;
58+
setTitle(title: string, init?: { from: string }): void;
59+
get fromCacheStorage(): boolean;
60+
public setPin(pin: number): void;
61+
public delete(): void;
62+
public patch(t: unknown): void;
63+
public patchChanges(
64+
t: unknown,
65+
init?: { from: string },
66+
): Promise<unknown>;
67+
get hasSelfBackLink(): boolean;
68+
public requestFetchApiCacheToServiceWorker(): unknown;
69+
}

0 commit comments

Comments
 (0)