11import { ParsedLine } from "./userscript/blocks.ts" ;
22import { StringLc } from "./base.ts" ;
3+ import type { Layout , PartialLayout } from "./layout.ts" ;
4+ import type { AddMenuInit , Item , PageMenu } from "./pageMenu.ts" ;
5+ import type { EventEmitter } from "./deps/events.ts" ;
6+ export type { EventEmitter , Layout , ParsedLine , PartialLayout , StringLc } ;
7+ export * from "./pageMenu.ts" ;
38
4- export type Layout =
5- | "list"
6- | "page"
7- | "stream"
8- | "project-settings-billing-page"
9- | "project-settings-basic-page"
10- | "project-settings-members-page"
11- | "settings-profile-page"
12- | "settings-extensions-page"
13- | "settings-delete-account-page" ;
149export type Scrapbox =
10+ & EventEmitter
1511 & {
16- Project : {
17- name : string ;
18- pages : PageBrief [ ] ;
12+ PageMenu : {
13+ ( menuName ?: string ) : PageMenu ;
14+ addMenu : ( init : AddMenuInit ) => void ;
15+ /** Add a menu item to a particular Page Menu button
16+ *
17+ * @param item information used for a menu item
18+ */
19+ addItem : ( item : Item ) => void ;
20+ /** Add a separator to a particular Page Menu button */
21+ addSeparater : ( ) => void ;
22+ removeAllItems : ( ) => void ;
1923 } ;
20- TimeStamp : TimeStamp ;
2124 PopupMenu : {
22- addButton : (
23- props : {
24- title : string | ( ( selectedText : string ) => string ) ;
25- onClick : ( selectedText : string ) => string | undefined ;
26- } ,
27- ) => void ;
25+ addButton : ( button : {
26+ title : string | ( ( text : string ) => ( string | undefined ) ) ;
27+ onClick : ( text : string ) => ( string | undefined ) ;
28+ } ) => void ;
2829 } ;
29- PageMenu : ( ( name : string ) => PageMenu ) & {
30- addMenu : (
31- props : { title : string ; image : string ; onClick ?: ( ) => void } ,
32- ) => void ;
33- addItem : ( props : AddItemProps ) => void ;
34- addSeparator : ( ) => void ;
35- removeAllItems : ( ) => void ;
30+ TimeStamp : TimeStamp ;
31+ Project : {
32+ get name ( ) : string ;
33+ get pages ( ) : PageBrief [ ] ;
3634 } ;
3735 }
38- & UserScriptEventTarget
39- & ( {
40- Layout :
41- | "list"
42- | "stream"
43- | "project-settings-billing-page"
44- | "project-settings-basic-page"
45- | "project-settings-members-page"
46- | "settings-profile-page"
47- | "settings-extensions-page"
48- | "settings-delete-account-page" ;
49- Page : {
50- title : null ;
51- lines : null ;
52- id : null ;
53- } ;
54- } | {
55- Layout : "page" ;
56- Page : {
57- title : string ;
58- lines : ParsedLine [ ] ;
59- id : string ;
60- } ;
61- } ) ;
36+ & (
37+ {
38+ Layout : "page" ;
39+ Page : {
40+ get lines ( ) : ParsedLine [ ] ;
41+ get title ( ) : string ;
42+ get id ( ) : string ;
43+ } ;
44+ } | {
45+ Layout : PartialLayout ;
46+ Page : {
47+ get lines ( ) : null ;
48+ get title ( ) : null ;
49+ get id ( ) : null ;
50+ } ;
51+ }
52+ ) ;
6253
63- export interface UserScriptEventTarget {
64- /** Register an event listener to Scrapbox
65- *
66- * @param type the event type the event listener registers to
67- * @param the event listener
68- */
69- addListener : ( type : string , listener : ( ) => void ) => void ;
70- /** Register an event listener to Scrapbox
71- *
72- * @param type the event type the event listener registers to
73- * @param the event listener
74- */
75- on : ( type : string , listener : ( ) => void ) => void ;
76- removeListener : ( type : string , listener : ( ) => void ) => void ;
77- off : ( type : string , listener : ( ) => void ) => void ;
78- removeAllListeners : ( type ?: string ) => void ;
79- once : ( type : string , listener : ( ) => void ) => void ;
80- prependListener : ( type : string , listener : ( ) => void ) => void ;
81- prependOnceListener : ( type : string , listener : ( ) => void ) => void ;
82- listeners : ( type : string ) => ( ( ) => void ) [ ] ;
83- rawListeners : ( type : string ) => ( ( ) => void ) [ ] ;
84- listenerCount : ( type : string ) => number ;
85- emit : ( type : string ) => void ;
86- eventNames : ( ) => string [ ] ;
87- getMexListeners : ( ) => number ;
88- setMexListeners : ( length : number ) => void ;
89- }
9054export interface PageBrief {
9155 /** true when the page has contents */ exists : boolean ;
9256 /** whether the page contains any image */ hasIcon ?: boolean ;
@@ -109,37 +73,6 @@ export interface TimeStamp {
10973 removeAllFormat : ( ) => void ;
11074}
11175
112- export interface AddItemProps {
113- /** the title of a menu item */ title : string | ( ( ) => string ) ;
114- /** the URL of an image which views on the left of the title */
115- image ?: string ;
116- /** the event listener which is executed when the menu item is clicked */
117- onClick : ( ) => void ;
118- }
119- export interface PageMenu {
120- /** Add a menu item to a particular Page Menu button
121- *
122- * @param props information used for a menu item
123- */
124- addItem : (
125- props : AddItemProps ,
126- ) => void ;
127- /** Add a separator to a particular Page Menu button */
128- addSeparator : ( ) => void ;
129- removeAllItems : ( ) => void ;
130- menuName : string ;
131- reset : ( ) => void ;
132- emitChange : ( ) => void ;
133- menus : Map <
134- string ,
135- {
136- image : string | null ;
137- onClick ?: ( ) => void ;
138- items : ( AddItemProps & { separator : boolean } ) [ ] ;
139- }
140- > ;
141- }
142-
14376/** built-in UserScript events */
14477export type eventName =
14578 | "lines:changed"
0 commit comments