|
5 | 5 |
|
6 | 6 | import type { Line } from "./blocks.ts"; |
7 | 7 | import type { BasePage, StringLc } from "./base.ts"; |
8 | | -import type { PartialLayout } from "./layout.ts"; |
| 8 | +import type { Layout, PartialLayout } from "./layout.ts"; |
9 | 9 | import type { AddMenuInit, Item, PageMenu } from "./pageMenu.ts"; |
10 | 10 | import type { EventEmitter } from "./deps/events.ts"; |
11 | 11 |
|
12 | 12 | /** Type definition of `window.scrapbox` */ |
13 | 13 | export type Scrapbox = |
14 | 14 | & EventEmitter |
15 | 15 | & { |
16 | | - PageMenu: { |
17 | | - /** get a particular Page Menu |
18 | | - * |
19 | | - * @param menuName Page Menu name to get. If it is set to "default" or undefined, return the default page Menu |
20 | | - */ |
21 | | - (menuName?: string): PageMenu; |
22 | | - /** Add a new Page Menu button |
23 | | - * |
24 | | - * @param init information used for a Page Menu button |
25 | | - */ |
26 | | - addMenu: (init: AddMenuInit) => void; |
27 | | - /** Add a menu item to the default Page Menu button |
28 | | - * |
29 | | - * @param item information used for a menu item |
30 | | - */ |
31 | | - addItem: (item: Item) => void; |
32 | | - /** Add a separator to the default Page Menu button */ |
33 | | - addSeparater: () => void; |
34 | | - /** remove all custom items from the default Page Menu button */ |
35 | | - removeAllItems: () => void; |
36 | | - }; |
37 | | - PopupMenu: { |
38 | | - /** Add a popup button |
39 | | - * |
40 | | - * @param button button settings |
41 | | - */ |
42 | | - addButton: (button: { |
43 | | - /** ボタンのタイトル |
44 | | - * |
45 | | - * 関数を設定して、選択範囲が変わるたびにタイトルを変更させる事もできる |
46 | | - */ |
47 | | - title: string | ((text: string) => (string | undefined)); |
48 | | - /** ボタンをクリックしたときに実行する処理 |
49 | | - * |
50 | | - * @return ここで返した文字列で選択範囲を置換し、popupを閉じる。`undefined`を返した場合は何もしない。popupも閉じない |
51 | | - */ |
52 | | - onClick: (text: string) => (string | undefined); |
53 | | - }) => void; |
54 | | - }; |
| 16 | + PageMenu: ExposedPageMenu; |
| 17 | + PopupMenu: PopupMenu; |
55 | 18 | TimeStamp: TimeStamp; |
56 | | - Project: { |
57 | | - /** get the current project name */ |
58 | | - get name(): string; |
59 | | - /** get the dictionary used for comupletion */ |
60 | | - get pages(): Candidate[]; |
61 | | - }; |
| 19 | + Project: Project; |
62 | 20 | } |
63 | 21 | & ( |
64 | 22 | { |
65 | 23 | /** the current page layout */ |
66 | 24 | Layout: "page"; |
67 | | - Page: { |
68 | | - /** get the current page lines data */ |
69 | | - get lines(): Line[]; |
70 | | - /** get the current page title */ |
71 | | - get title(): string; |
72 | | - /** get the current page id */ |
73 | | - get id(): string; |
74 | | - }; |
| 25 | + Page: Page<"page">; |
75 | 26 | } | { |
76 | 27 | /** the current page layout */ |
77 | 28 | Layout: PartialLayout; |
78 | | - Page: { |
79 | | - get lines(): null; |
80 | | - get title(): null; |
81 | | - get id(): null; |
82 | | - }; |
| 29 | + Page: Page<PartialLayout>; |
83 | 30 | } |
84 | 31 | ); |
85 | 32 |
|
86 | | -/** 入力補完に使われる辞書 */ |
87 | | -export interface Candidate extends Pick<BasePage, "id" | "title" | "updated"> { |
88 | | - /** true when the page has contents */ exists: boolean; |
89 | | - /** whether the page contains any image */ hasIcon?: boolean; |
90 | | - /** lower case style of the page title */ titleLc: StringLc; |
| 33 | +/** `window.scrapbox`に露出している`PageMenu`の型 */ |
| 34 | +export interface ExposedPageMenu { |
| 35 | + /** get a particular Page Menu |
| 36 | + * |
| 37 | + * @param menuName Page Menu name to get. If it is set to "default" or undefined, return the default page Menu |
| 38 | + */ |
| 39 | + (menuName?: string): PageMenu; |
| 40 | + |
| 41 | + /** Add a new Page Menu button |
| 42 | + * |
| 43 | + * @param init information used for a Page Menu button |
| 44 | + */ |
| 45 | + addMenu: (init: AddMenuInit) => void; |
| 46 | + |
| 47 | + /** Add a menu item to the default Page Menu button |
| 48 | + * |
| 49 | + * @param item information used for a menu item |
| 50 | + */ |
| 51 | + addItem: (item: Item) => void; |
| 52 | + |
| 53 | + /** Add a separator to the default Page Menu button */ |
| 54 | + addSeparater: () => void; |
| 55 | + |
| 56 | + /** remove all custom items from the default Page Menu button */ |
| 57 | + removeAllItems: () => void; |
| 58 | +} |
| 59 | + |
| 60 | +/** `window.scrapbox`に露出している`PopupMenu`の型 */ |
| 61 | +export interface PopupMenu { |
| 62 | + /** Add a popup button |
| 63 | + * |
| 64 | + * @param button button settings |
| 65 | + */ |
| 66 | + addButton: (button: { |
| 67 | + /** ボタンのタイトル |
| 68 | + * |
| 69 | + * 関数を設定して、選択範囲が変わるたびにタイトルを変更させる事もできる |
| 70 | + */ |
| 71 | + title: string | ((text: string) => (string | undefined)); |
| 72 | + /** ボタンをクリックしたときに実行する処理 |
| 73 | + * |
| 74 | + * @return ここで返した文字列で選択範囲を置換し、popupを閉じる。`undefined`を返した場合は何もしない。popupも閉じない |
| 75 | + */ |
| 76 | + onClick: (text: string) => (string | undefined); |
| 77 | + }) => void; |
91 | 78 | } |
92 | 79 |
|
| 80 | +/** `window.scrapbox`に露出している`TimeStamp`の型 */ |
93 | 81 | export interface TimeStamp { |
94 | 82 | /** Add a timestamp format to Scrapbox |
95 | 83 | * |
96 | 84 | * @param format a format of timestamp. this follow the moment.js format. You can set a function which returns any string |
97 | 85 | */ |
98 | 86 | addFormat: (format: string | (() => string)) => void; |
| 87 | + |
99 | 88 | /** Remove all timestamp formats from Scrapbox |
100 | 89 | * |
101 | 90 | * These include default formats |
102 | 91 | */ |
103 | 92 | removeAllFormat: () => void; |
104 | 93 | } |
| 94 | + |
| 95 | +/** 入力補完に使われる辞書 */ |
| 96 | +export interface Candidate extends Pick<BasePage, "id" | "title" | "updated"> { |
| 97 | + /** true when the page has contents */ |
| 98 | + exists: boolean; |
| 99 | + |
| 100 | + /** whether the page contains any image */ |
| 101 | + hasIcon?: boolean; |
| 102 | + |
| 103 | + /** lower case style of the page title */ |
| 104 | + titleLc: StringLc; |
| 105 | +} |
| 106 | + |
| 107 | +/** `window.scrapbox`に露出している`Project`の型 */ |
| 108 | +export interface Project { |
| 109 | + /** get the current project name */ |
| 110 | + get name(): string; |
| 111 | + |
| 112 | + /** get the dictionary used for comupletion */ |
| 113 | + get pages(): Candidate[]; |
| 114 | +} |
| 115 | + |
| 116 | +/** `window.scrapbox`に露出している`Page`の型 */ |
| 117 | +export interface Page<T extends Layout> { |
| 118 | + /** get the current page lines data */ |
| 119 | + get lines(): T extends "page" ? Line[] : null; |
| 120 | + |
| 121 | + /** get the current page title */ |
| 122 | + get title(): T extends "page" ? string : null; |
| 123 | + |
| 124 | + /** get the current page id */ |
| 125 | + get id(): T extends "page" ? string : null; |
| 126 | +} |
0 commit comments