From f69a161d03567e238db128a8a439a0b41f52ec96 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Sat, 24 Jul 2021 20:16:41 +0900 Subject: [PATCH 1/3] :construction::sparkles: Add almost all types of properties in `scrapbox` --- scrapbox.d.ts | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 scrapbox.d.ts diff --git a/scrapbox.d.ts b/scrapbox.d.ts new file mode 100644 index 0000000..d004be8 --- /dev/null +++ b/scrapbox.d.ts @@ -0,0 +1,86 @@ +export type Layout = + | "list" + | "page" + | "stream" + | "project-settings-billing-page" + | "project-settings-basic-page" + | "project-settings-members-page" + | "settings-profile-page" + | "settings-extensions-page" + | "settings-delete-account-page"; +export type Scrapbox = + & { + Project: { + name: string; + pages: PageBrief[]; + }; + TimeStamp: TimeStamp; + PopupMenu?: { + addButton: ( + props: { + title: string | ((selectedText: string) => string); + onClick: (selectedText: string) => string | undefined; + }, + ) => void; + }; + addListener: (type: string, listener: () => void) => void; + on: (type: string, listener: () => void) => void; + removeListener: (type: string, listener: () => void) => void; + off: (type: string, listener: () => void) => void; + removeAllListeners: (type?: string) => void; + once: (type: string, listener: () => void) => void; + prependListener: (type: string, listener: () => void) => void; + prependOnceListener: (type: string, listener: () => void) => void; + listeners: (type: string) => (() => void)[]; + rawListeners: (type: string) => (() => void)[]; + listenerCount: (type: string) => number; + emit: (type: string) => void; + eventNames: () => string[]; + getMexListeners: () => number; + setMexListeners: (length: number) => void; + } + & ({ + Layout: + | "list" + | "stream" + | "project-settings-billing-page" + | "project-settings-basic-page" + | "project-settings-members-page" + | "settings-profile-page" + | "settings-extensions-page" + | "settings-delete-account-page"; + Page: { + title: null; + lines: null; + id: null; + }; + } | { + Layout: "page"; + Page: { + title: string; + lines: ParsedLine[]; + id: string; + }; + }); + +export type PageBrief = { + exists: boolean; + hasIcon?: boolean; + id: string; + title: string; + titleLc: string; + updated: number; +}; + +export type ParsedLine = {}; + +type TimeStamp = { + addFormat: (format: string | (() => string)) => void; + removeAllFormat: () => void; +}; + +export type eventName = + | "lines:changed" + | "page:changed" + | "layout:changed" + | "project:changed"; From 726edf9f63b7b8dde0fac96106bdbe06d8c03367 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Sun, 25 Jul 2021 14:49:30 +0900 Subject: [PATCH 2/3] :sparkles: Add `scrapbox.Page.lines` without detailed syntax information --- scrapbox.d.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scrapbox.d.ts b/scrapbox.d.ts index d004be8..e856305 100644 --- a/scrapbox.d.ts +++ b/scrapbox.d.ts @@ -72,7 +72,19 @@ export type PageBrief = { updated: number; }; -export type ParsedLine = {}; +export type ParsedLine = { + text: string; + id: string; + userId: string; + updated: number; + created: number; + section: { + number: number; + start: boolean; + end: boolean; + }; + title?: boolean; +}; type TimeStamp = { addFormat: (format: string | (() => string)) => void; From e40ddbeda1385c9fcf69b9ae5bbae6e09201c86b Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Sun, 25 Jul 2021 15:16:29 +0900 Subject: [PATCH 3/3] :sparkles: Add the type of `scrapbox.PageMenu` --- scrapbox.d.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/scrapbox.d.ts b/scrapbox.d.ts index e856305..d06a398 100644 --- a/scrapbox.d.ts +++ b/scrapbox.d.ts @@ -23,6 +23,14 @@ export type Scrapbox = }, ) => void; }; + PageMenu: ((name: string) => PageMenu) & { + addMenu: ( + props: { title: string; image: string; onClick?: () => void }, + ) => void; + addItem: (props: AddItemProps) => void; + addSeparator: () => void; + removeAllItems: () => void; + }; addListener: (type: string, listener: () => void) => void; on: (type: string, listener: () => void) => void; removeListener: (type: string, listener: () => void) => void; @@ -91,6 +99,30 @@ type TimeStamp = { removeAllFormat: () => void; }; +type AddItemProps = { + title: string | (() => string); + image?: string; + onClick: () => void; +}; +type PageMenu = { + addItem: ( + props: AddItemProps, + ) => void; + addSeparator: () => void; + removeAllItems: () => void; + menuName: string; + reset: () => void; + emitChange: () => void; + menus: Map< + string, + { + image: string | null; + onClick?: () => void; + items: (AddItemProps & { separator: boolean })[]; + } + >; +}; + export type eventName = | "lines:changed" | "page:changed"