diff --git a/base.ts b/base.ts index c113bca..92891d5 100644 --- a/base.ts +++ b/base.ts @@ -3,8 +3,8 @@ export interface Line { /** 行のid */ id: LineId; /** 行のテキスト */ text: string; /** 一番最後に行を編集した人のid */ userId: UserId; - /** 行の作成日時 */ created: number; - /** 行の最終更新日時 */ updated: number; + /** 行の作成日時 */ created: UnixTime; + /** 行の最終更新日時 */ updated: UnixTime; } /** basic information about a page */ @@ -20,8 +20,8 @@ export interface Page { * the maximum number of lines is 5. */ descriptions: string[]; - /** ページの最終更新日時 */ updated: number; - /** Date last visitedに使われる最終アクセス日時 */ accessed: number; + /** ページの最終更新日時 */ updated: UnixTime; + /** Date last visitedに使われる最終アクセス日時 */ accessed: UnixTime; } /** the user id */ @@ -41,3 +41,5 @@ export type ProjectId = string; * - UPPER CASE -> upper_case */ export type StringLc = string; +/** UNIX time */ +export type UnixTime = number; diff --git a/userscript/blocks.ts b/blocks.ts similarity index 57% rename from userscript/blocks.ts rename to blocks.ts index 9835606..1a868fc 100644 --- a/userscript/blocks.ts +++ b/blocks.ts @@ -1,17 +1,21 @@ -import { Node, NodeWithoutIndent } from "./nodes.ts"; -import { Line } from "../base.ts"; +import type { Node, NodeWithoutIndent } from "./nodes.ts"; +import type { Line as LineBase } from "./base.ts"; -export type ParsedLine = - & Line +export type Line = + & LineBase & { section: { + /** section number */ number: number; + /** section開始行なら`true` */ start: boolean; + /** section終了行なら`true` */ end: boolean; }; } & ({ - title?: boolean; + /** タイトル行だったときのみ生える */ + title?: true; } | { codeBlock: CodeBlock; } | { @@ -21,12 +25,15 @@ export type ParsedLine = } | { cli: Cli; } | { + /** 番号付きリストのときのみ生える */ + numberList?: { + /** 番号の長さ */ + digit: number; + }; + /** 数式を含む行のときのみ生える */ formulaLine?: true; - nodes: NodeWithoutIndent[]; - } | { - numberList?: { digit: number }; - formulaLine?: true; - nodes: Node[]; + /** 中に含まれるnodes */ + nodes: Node | NodeWithoutIndent[]; }); /** the type which represents a line in a block */ @@ -47,11 +54,17 @@ export interface TableBlock extends Block { /** the title of the table block */ title: string; /** cells included in the present line */ cells: string[]; } -export type Helpfeel = { + +/** Helpfeel記法 */ +export interface Helpfeel { prefix: "?"; + /** Helpfeel本文 */ entry: string; -}; -export type Cli = { +} + +/** Command Line記法 */ +export interface Cli { prefix: "$" | "%"; + /** Command Line本文 */ command: string; -}; +} diff --git a/api/error.ts b/error.ts similarity index 89% rename from api/error.ts rename to error.ts index 06ffa92..2edbb43 100644 --- a/api/error.ts +++ b/error.ts @@ -1,4 +1,7 @@ -/** Scrapbox REST APIが返すエラーの型 */ +/** Scrapbox REST APIが返すエラーの型 + * + * `name`はないことがある + */ export interface ErrorLike { /** error name */ name: string; /** error message */ message: string; @@ -22,8 +25,10 @@ export interface NotPrivilegeError extends ErrorLike { /** Loginが必要なAPIをloginせずに叩いたときに発生するエラー */ export interface NotLoggedInError extends ErrorLike { name: "NotLoggedInError"; - /** 詳細情報 */ details: { - /** 使用できるログイン方法 */ loginStrategies: ( + /** 詳細情報 */ + details: { + /** 使用できるログイン方法 */ + loginStrategies: ( | "google" | "github" | "microsoft" diff --git a/eventName.ts b/eventName.ts new file mode 100644 index 0000000..0d5d574 --- /dev/null +++ b/eventName.ts @@ -0,0 +1,14 @@ +/** built-in UserScript events + * + * | Event | Description | + * | ------ | ----------- | + * | lines:changed | 今開いているページの文章が変更された | + * | page:changed | 別のページに遷移した | + * | layout:changed | 別の種類のページに遷移した | + * | project:changed | 別のprojectに遷移した | + */ +export type eventName = + | "lines:changed" + | "page:changed" + | "layout:changed" + | "project:changed"; diff --git a/mod.ts b/mod.ts index 167a6de..93d919f 100644 --- a/mod.ts +++ b/mod.ts @@ -1,5 +1,6 @@ -export * from "./api/response.ts"; -export * from "./api/error.ts"; -export * from "./userscript.ts"; -export * from "./userscript/blocks.ts"; -export * from "./userscript/nodes.ts"; +export * from "./response.ts"; +export * from "./error.ts"; +export * from "./error.ts"; +export type { Scrapbox } from "./userscript.ts"; +import * as UserScript from "./userscript.ts"; +export { UserScript }; diff --git a/nodes.ts b/nodes.ts new file mode 100644 index 0000000..3ddd8a8 --- /dev/null +++ b/nodes.ts @@ -0,0 +1,400 @@ +export type NodeWithoutIndent = + | PlainText + | Blank + | Video + | Vimeo + | Decoration + | Link + | Quote + | Code + | Audio + | AudioLink + | Image + | StrongImage + | Gyazo + | StrongGyazo + | ImageLink + | StrongImageLink + | GyazoLink + | StrongGyazoLink + | Strong + | Icon + | StrongIcon + | Url + | UrlLink + | Youtube + | GoogleMap + | Formula; + +export type Node = NodeWithoutIndent | Indent; + +export interface UnitBase { + /** 記法を取り除いたテキスト */ + content: string; + /** 記法を取り除いていない生のテキスト */ + whole: string; +} + +/** plain text node */ +export type PlainText = string; + +/** インデントがある行 */ +export interface Indent { + type: "indent"; + /** 構文解析結果 */ + unit: UnitBase & { + /** インデントに使われている空白 */ + tag: string; + }; + /** 中に含まれるNodes */ + children: NodeWithoutIndent | NodeWithoutIndent[]; +} + +/** 空白記法 */ +export interface Blank { + type: "blank"; + /** 構文解析結果 */ + unit: UnitBase; + /** the same as `unit.content` */ + children: PlainText; +} + +/** リンク記法 + * + * 以下の形式が対象 + * + * - [aaa] + * - [/xxx/aaa] + * - [/xxx/] + * - [/xxx] + */ +export interface Link { + type: "link"; + /** 構文解析結果 */ + unit: + & UnitBase + & ({ + /** page title */ + page: string; + } | { + /** project name */ + project: string; + /** page title */ + page: string; + } | { + /** project name */ + project: string; + }); + /** the same as `unit.content` */ + children: PlainText; +} + +/** 裸のURL */ +export interface Url { + type: "url"; + /** 構文解析結果 */ + unit: UnitBase; + /** scrapboxにuploadされたfileのID + * + * このpropertyはscrapboxにuploadされたファイルのときのみ生える + */ + fileId?: string; + /** the same as `unit.content` */ + children: PlainText; +} + +/** 外部リンク記法 */ +export interface UrlLink { + type: "urlLink"; + /** 構文解析結果 */ + unit: UnitBase & { + /** URL */ + link: string; + /** タイトル */ + title?: string; + }; + /** scrapboxにuploadされたfileのID + * + * このpropertyはscrapboxにuploadされたファイルのときのみ生える + */ + fileId?: string; + /** the same as `unit.content` */ + children: PlainText; +} + +/** 引用記法 */ +export interface Quote { + type: "quote"; + /** 構文解析結果 */ + unit: UnitBase & { + /** 引用記号とそれに続く空白を含んだもの */ + tag: `>${string}`; + }; + /** 中に含まれるNodes */ + children: NodeWithoutIndent | NodeWithoutIndent[]; +} + +/** コード記法 */ +export interface Code { + type: "code"; + /** 構文解析結果 */ + unit: UnitBase; + /** the same as `unit.content` */ + children: PlainText; +} + +/** アイコン記法 */ +export interface Icon extends IconBase { + type: "icon"; +} + +/** 強調アイコン記法 */ +export interface StrongIcon extends IconBase { + type: "strong-icon"; +} + +export interface IconBase { + /** 構文解析結果 */ + unit: UnitBase & { + /** アイコンがあるproject name + * + * 同じprojectのアイコンのときは省略される + */ + project?: string; + /** アイコンがあるページのタイトル */ + page: string; + /** 繰り返し回数 + * + * 最大1000 + */ + size: number; + }; + /** the same as `unit.content` */ + children: PlainText; +} + +/** 数式記法 */ +export interface Formula { + type: "deco-formula"; + /** 構文解析結果 */ + unit: UnitBase & { + /** KaTeX text + * + * `content` から`$ `を外したもの + */ + formula: string; + }; + /** the same as `unit.content` */ + children: PlainText; +} + +/** 強調記法 */ +export interface Strong { + type: "strong"; + /** 構文解析結果 */ + unit: UnitBase; + /** 中に含まれるNode */ + children: NodeWithoutIndent; +} +/** 文字装飾記法 */ +export interface Decoration { + type: "deco"; + /** 構文解析結果 */ + unit: UnitBase & { + /** 文字装飾記号 */ + deco: string; + /** 強調のレベル + * + * `*`が一つ増えるごとに1増える + * + * 一つもないときは`0`になる + */ + strong: number; + /** 斜体記号`/`を含むとき`true` */ + italic: boolean; + /** 打ち消し記号`-`を含むとき`true` */ + strike: boolean; + /** 下線記号`_`を含むとき`true` */ + underline: boolean; + }; + /** 中に含まれるNode */ + children: NodeWithoutIndent; +} + +// 埋め込み系 + +/** 画像記法 */ +export interface Image extends ImageBase { + type: "image"; +} + +/** 強調画像記法 */ +export interface StrongImage extends ImageBase { + type: "strongImage"; +} + +export interface ImageBase { + /** 構文解析結果 */ + unit: UnitBase; + /** scrapboxにuploadされたfileのID + * + * このpropertyはscrapboxにuploadされた画像ファイルのときのみ生える + */ + fileId?: string; + /** the same as `unit.content` */ + children: PlainText; +} + +/** Gyazoから引っ張ってきた画像の画像記法 */ +export interface Gyazo extends GyazoBase { + type: "gyazo"; +} + +/** Gyazoから引っ張ってきた画像の強調画像記法 */ +export interface StrongGyazo extends GyazoBase { + type: "strongGyazo"; +} +export interface GyazoBase { + /** 構文解析結果 */ + unit: UnitBase; + /** the same as `unit.content` */ + children: PlainText; +} + +/** リンク付き画像記法 */ +export interface ImageLink extends ImageLinkBase { + type: "imageLink"; +} +/** リンク付き強調画像記法 */ +export interface StrongImageLink extends ImageLinkBase { + type: "strongImageLink"; +} +export interface ImageLinkBase { + /** 構文解析結果 */ + unit: UnitBase & { + /** 画像のURL */ + image: string; + /** 埋め込まれたリンクのURL */ + link: string; + }; + /** the same as `unit.content` */ + children: PlainText; +} + +/** Gyazoから引っ張ってきた画像のリンク付き画像記法 */ +export interface GyazoLink extends GyazoLinkBase { + type: "gyazoLink"; +} +/** Gyazoから引っ張ってきた画像のリンク付き強調画像記法 */ +export interface StrongGyazoLink extends GyazoLinkBase { + type: "strongGyazoLink"; +} +export interface GyazoLinkBase { + /** 構文解析結果 */ + unit: UnitBase & { + /** 画像のURL */ + gyazo: string; + /** 埋め込まれたリンクのURL */ + link: string; + }; + /** the same as `unit.content` */ + children: PlainText; +} + +/** 動画埋め込み */ +export interface Video { + type: "video"; + /** 構文解析結果 */ + unit: UnitBase; + /** scrapboxにuploadされたfileのID + * + * このpropertyはscrapboxにuploadされた動画ファイルのときのみ生える + */ + fileId?: string; + /** the same as `unit.content` */ + children: PlainText; +} +/** Youtube埋め込み */ +export interface Youtube { + type: "youtube"; + /** 構文解析結果 */ + unit: + & UnitBase + & { + /** URL parameters */ + params: Record & { t?: number }; + } + & ({ + /** Youtube video ID */ + videoId: string; + } | { + /** Youtube playlist ID + * + * `/playlist?list=xxx`の形のURLのときのみ生える + */ + listId: string; + }); + /** the same as `unit.content` */ + children: PlainText; +} +/** Vimeo埋め込み */ +export interface Vimeo { + type: "vimeo"; + /** 構文解析結果 */ + unit: UnitBase & { + /** vimeoのvideo id */ + videoId: string; + }; + /** the same as `unit.content` */ + children: PlainText; +} + +/** 音声埋め込み */ +export interface Audio { + type: "audio"; + /** 構文解析結果 */ + unit: UnitBase; + /** scrapboxにuploadされたfileのID + * + * このpropertyはscrapboxにuploadされた音声ファイルのときのみ生える + */ + fileId?: string; + /** the same as `unit.content` */ + children: PlainText; +} +/** タイトル付き音声 */ +export interface AudioLink { + type: "audioLink"; + /** 構文解析結果 */ + unit: UnitBase & { + /** 音声のURL */ + link: string; + /** 音声のタイトル */ + title: string; + }; + /** scrapboxにuploadされたfileのID + * + * このpropertyはscrapboxにuploadされた音声ファイルのときのみ生える + */ + fileId?: string; + /** the same as `unit.content` */ + children: PlainText; +} + +/** Location記法 */ +export interface GoogleMap { + type: "location"; + /** 構文解析結果 */ + unit: UnitBase & { + /** 緯度 */ + latitude: number; + /** 経度 */ + longitude: number; + /** 拡大レベル */ + zoom: number; + /** 地点の名前 */ + title?: string; + }; + /** the same as `unit.content` */ + children: PlainText; +} diff --git a/api/response.ts b/response.ts similarity index 86% rename from api/response.ts rename to response.ts index 39c8000..7da921c 100644 --- a/api/response.ts +++ b/response.ts @@ -5,8 +5,9 @@ import { PageId, ProjectId, StringLc, + UnixTime, UserId, -} from "../base.ts"; +} from "./base.ts"; /** 関連ページのメタデータ */ export interface RelatedPage extends PageBase { @@ -27,8 +28,8 @@ export interface UserInfo extends User { /** user e-mail */ email: string; /** whether the user is a pro user or not */ pro: boolean; /** login provider */ provider: "google" | "microsoft" | "email"; - /** accountの作成日時 */ created: number; - /** accountの更新日時 */ updated: number; + /** accountの作成日時 */ created: UnixTime; + /** accountの更新日時 */ updated: UnixTime; } /** summary of page information */ @@ -37,27 +38,31 @@ export interface PageSummary extends PageBase { /** ページの閲覧回数 */ views: number; /** おそらく被リンク数 */ linked: number; /** 最新の編集コミットid */ commitId: CommitId; - /** ページの作成日時 */ created: number; + /** ページの作成日時 */ created: UnixTime; /** page rank */ pageRank: number; - /** Page historyの最終生成日時 */ snapshotCreated: number | null; + /** Page historyの最終生成日時 */ snapshotCreated: UnixTime | null; } /** page information */ export interface Page extends PageSummary { - /** APIを叩いたuserの最終アクセス日時。おそらくこの値を元にテロメアの未読/既読の判別をしている */ lastAccessed: - | number - | null; + /** APIを叩いたuserの最終アクセス日時。 + * + * おそらくこの値を元にテロメアの未読/既読の判別をしている + */ + lastAccessed: UnixTime | null; /** 生成されたPage historyの数 */ snapshotCount: number; /** 不明。削除されたページだとfalse? */ persistent: boolean; /** ページの行情報 */ lines: Line[]; /** ページ内のリンク */ links: string[]; /** ページ内のアイコン */ icons: string[]; - /** ページ内に含まれる、scrapbox.ioにアップロードしたファイルへのリンク */ files: string[]; + /** ページ内に含まれる、scrapbox.ioにアップロードしたファイルへのリンク */ + files: string[]; /** 関連ページリスト */ relatedPages: { /** 1 hop links */ links1hop: RelatedPage[]; /** 2 hop links */ links2hop: RelatedPage[]; - /** このページを参照しているページorアイコンがあればtrue */ hasBackLinksOrIcons: boolean; + /** このページを参照しているページorアイコンがあればtrue */ + hasBackLinksOrIcons: boolean; }; /** 最後にページを更新したユーザー */ user: User; /** ページを編集したユーザーのうち、`user`以外の人 */ collaborators: User[]; @@ -83,8 +88,8 @@ export interface NotMemberProject { gyazoTeamsName: string | null; googleAnalyticsCode: string | null; image?: string; - created: number; - updated: number; + created: UnixTime; + updated: UnixTime; isMember: false; } @@ -101,7 +106,7 @@ export interface MemberProject extends Omit { uploadFileTo: "gcs"; uploadImaegTo: "gyazo" | "gcs"; emailAddressPatterns: string[]; - backuped: number | null; + backuped: UnixTime | null; } export interface GuestUser { @@ -122,20 +127,15 @@ export interface MemberUser extends UserInfo { export type UserResponse = GuestUser | MemberUser; /** the response type of https://scrapbox.io/api/pages/:projectname/search/titles */ -export interface SearchedTitle { - id: PageId; - /** page title */ title: string; +export interface SearchedTitle + extends Pick { /** 画像が存在するかどうか */ hasIcon: boolean; - /** ページの更新日時 */ updated: number; /** ページ内のリンク */ links: string[]; } /** exportもしくはbackupをとったときのページデータ */ -export interface ExportedPage { - /** page's title */ title: string; - /** ページの最終更新日時 (UNIX時刻) */ updated: number; - /** ページの最終作成日時 (UNIX時刻) */ created: number; - /** page ID */ id: string; +export interface ExportedPage + extends Pick { /** ページ本文 * * `hasMetadata === true`のときは行のmetadataが入る @@ -148,7 +148,7 @@ export interface ExportedPage { export interface ExportedData { /** project's name */ name: string; /** project's display name */ displayName: string; - /** このデータを生成した日時 (UNIX時刻) */ exported: number; + /** このデータを生成した日時 (UNIX時刻) */ exported: UnixTime; /** exported pages */ pages: ExportedPage[]; } @@ -168,8 +168,8 @@ export interface ImportedLightPage { /** インポート用メタデータ付き行データ */ export interface ImportedLine { /** line text */ text: string; - /** 行の最終更新日時 (UNIX時刻) */ updated?: number; - /** 行の最終作成日時 (UNIX時刻) */ created?: number; + /** 行の最終更新日時 (UNIX時刻) */ updated?: UnixTime; + /** 行の最終作成日時 (UNIX時刻) */ created?: UnixTime; } /** メタデータ付きインポート用ページデータ */ export interface ImportedPage { diff --git a/scrapbox.ts b/scrapbox.ts new file mode 100644 index 0000000..c662ccf --- /dev/null +++ b/scrapbox.ts @@ -0,0 +1,104 @@ +/// +/// +/// +/// + +import type { Line } from "./blocks.ts"; +import type { Page as PageBase, StringLc } from "./base.ts"; +import type { PartialLayout } from "./layout.ts"; +import type { AddMenuInit, Item, PageMenu } from "./pageMenu.ts"; +import type { EventEmitter } from "./deps/events.ts"; + +/** Type definition of `window.scrapbox` */ +export type Scrapbox = + & EventEmitter + & { + PageMenu: { + /** get a particular Page Menu + * + * @param menuName Page Menu name to get. If it is set to "default" or undefined, return the default page Menu + */ + (menuName?: string): PageMenu; + /** Add a new Page Menu button + * + * @param init information used for a Page Menu button + */ + addMenu: (init: AddMenuInit) => void; + /** Add a menu item to the default Page Menu button + * + * @param item information used for a menu item + */ + addItem: (item: Item) => void; + /** Add a separator to the default Page Menu button */ + addSeparater: () => void; + /** remove all custom items from the default Page Menu button */ + removeAllItems: () => void; + }; + PopupMenu: { + /** Add a popup button + * + * @param button button settings + */ + addButton: (button: { + /** ボタンのタイトル + * + * 関数を設定して、選択範囲が変わるたびにタイトルを変更させる事もできる + */ + title: string | ((text: string) => (string | undefined)); + /** ボタンをクリックしたときに実行する処理 + * + * @return ここで返した文字列で選択範囲を置換し、popupを閉じる。`undefined`を返した場合は何もしない。popupも閉じない + */ + onClick: (text: string) => (string | undefined); + }) => void; + }; + TimeStamp: TimeStamp; + Project: { + /** get the current project name */ + get name(): string; + /** get the dictionary used for comupletion */ + get pages(): Page[]; + }; + } + & ( + { + /** the current page layout */ + Layout: "page"; + Page: { + /** get the current page lines data */ + get lines(): Line[]; + /** get the current page title */ + get title(): string; + /** get the current page id */ + get id(): string; + }; + } | { + /** the current page layout */ + Layout: PartialLayout; + Page: { + get lines(): null; + get title(): null; + get id(): null; + }; + } + ); + +/** 入力補完に使われる辞書 */ +export interface Page extends Pick { + /** true when the page has contents */ exists: boolean; + /** whether the page contains any image */ hasIcon?: boolean; + /** lower case style of the page title */ titleLc: StringLc; +} + +export interface TimeStamp { + /** Add a timestamp format to Scrapbox + * + * @param format a format of timestamp. this follow the moment.js format. You can set a function which returns any string + */ + addFormat: (format: string | (() => string)) => void; + /** Remove all timestamp formats from Scrapbox + * + * These include default formats + */ + removeAllFormat: () => void; +} diff --git a/userscript.ts b/userscript.ts index 1cebe78..4303ea1 100644 --- a/userscript.ts +++ b/userscript.ts @@ -1,124 +1,7 @@ -/// -/// -/// -/// - -import { ParsedLine } from "./userscript/blocks.ts"; -import { StringLc } from "./base.ts"; -import type { Layout, PartialLayout } from "./layout.ts"; -import type { AddMenuInit, Item, PageMenu } from "./pageMenu.ts"; -import type { EventEmitter } from "./deps/events.ts"; -export type { EventEmitter, Layout, ParsedLine, PartialLayout, StringLc }; +export * from "./blocks.ts"; +export * from "./nodes.ts"; +export * from "./layout.ts"; export * from "./pageMenu.ts"; - -/** Type definition of `window.scrapbox` */ -export type Scrapbox = - & EventEmitter - & { - PageMenu: { - /** get a particular Page Menu - * - * @param menuName Page Menu name to get. If it is set to "default" or undefined, return the default page Menu - */ - (menuName?: string): PageMenu; - /** Add a new Page Menu button - * - * @param init information used for a Page Menu button - */ - addMenu: (init: AddMenuInit) => void; - /** Add a menu item to the default Page Menu button - * - * @param item information used for a menu item - */ - addItem: (item: Item) => void; - /** Add a separator to the default Page Menu button */ - addSeparater: () => void; - /** remove all custom items from the default Page Menu button */ - removeAllItems: () => void; - }; - PopupMenu: { - /** Add a popup button - * - * @param button button settings - */ - addButton: (button: { - /** ボタンのタイトル - * - * 関数を設定して、選択範囲が変わるたびにタイトルを変更させる事もできる - */ - title: string | ((text: string) => (string | undefined)); - /** ボタンをクリックしたときに実行する処理 - * - * @return ここで返した文字列で選択範囲を置換し、popupを閉じる。`undefined`を返した場合は何もしない。popupも閉じない - */ - onClick: (text: string) => (string | undefined); - }) => void; - }; - TimeStamp: TimeStamp; - Project: { - /** get the current project name */ - get name(): string; - /** get the dictionary used for comupletion */ - get pages(): PageBrief[]; - }; - } - & ( - { - /** the current page layout */ - Layout: "page"; - Page: { - /** get the current page lines data */ - get lines(): ParsedLine[]; - /** get the current page title */ - get title(): string; - /** get the current page id */ - get id(): string; - }; - } | { - /** the current page layout */ - Layout: PartialLayout; - Page: { - get lines(): null; - get title(): null; - get id(): null; - }; - } - ); - -/** 入力補完に使われる辞書 */ -export interface PageBrief { - /** true when the page has contents */ exists: boolean; - /** whether the page contains any image */ hasIcon?: boolean; - /** the page id */ id: string; - /** the page title */ title: string; - /** lower case style of the page title */ titleLc: StringLc; - /** updated time */ updated: number; -} - -export interface TimeStamp { - /** Add a timestamp format to Scrapbox - * - * @param format a format of timestamp. this follow the moment.js format. You can set a function which returns any string - */ - addFormat: (format: string | (() => string)) => void; - /** Remove all timestamp formats from Scrapbox - * - * These include default formats - */ - removeAllFormat: () => void; -} - -/** built-in UserScript events - * - * | Event | Description | - * | ------ | ----------- | - * | lines:changed | 今開いているページの文章が変更された | - * | page:changed | 別のページに遷移した | - * | layout:changed | 別の種類のページに遷移した | - * | project:changed | 別のprojectに遷移した | - */ -export type eventName = - | "lines:changed" - | "page:changed" - | "layout:changed" - | "project:changed"; +export * from "./eventName.ts"; +export * from "./scrapbox.ts"; +export type { EventEmitter } from "./deps/events.ts"; diff --git a/userscript/nodes.ts b/userscript/nodes.ts deleted file mode 100644 index 02d702f..0000000 --- a/userscript/nodes.ts +++ /dev/null @@ -1,202 +0,0 @@ -type NodeBase = - | PlainText - | Blank - | Video - | Vimeo - | Decoration - | Link - | Quote - | Code - | Audio - | AudioLink - | Image - | StrongImage - | Gyazo - | StrongGyazo - | ImageLink - | StrongImageLink - | GyazoLink - | StrongGyazoLink - | Strong - | Icon - | StrongIcon - | Url - | UrlLink - | Youtube - | GoogleMap; -export type NodeWithoutIndent = NodeBase | Formula; -export type Node = NodeWithoutIndent | Indent; -type UnitBase = { - content: string; - whole: string; -}; -export type PlainText = string; -export type Blank = { - type: "blank"; - unit: UnitBase; - children: PlainText; -}; -export type Video = { - type: "video"; - unit: UnitBase; - fileId: string | undefined; - children: PlainText; -}; -export type Vimeo = { - type: "vimeo"; - unit: UnitBase & { - videoId: string; - }; - children: PlainText; -}; -export type Decoration = { - type: "deco"; - unit: UnitBase & { - deco: string; - strong: number; - italic: boolean; - strike: boolean; - underline: boolean; - }; - children: NodeWithoutIndent; -}; -export type Link = { - type: "link"; - unit: - & UnitBase - & ({ - page: string; - } | { - project: string; - page: string; - } | { - project: string; - }); - children: PlainText; -}; -export type Quote = { - type: "quote"; - unit: UnitBase & { - tag: string; - }; - children: NodeWithoutIndent; -}; -export type Code = { - type: "code"; - unit: UnitBase; - children: PlainText; -}; -export type Indent = { - type: "indent"; - unit: UnitBase & { - tag: string; - }; - children: NodeWithoutIndent; -}; -export type Audio = { - type: "audio"; - unit: UnitBase; - fileId: string | undefined; - children: PlainText; -}; -export type AudioLink = { - type: "audioLink"; - unit: UnitBase & { - link: string; - title: string; - }; - fileId: string | undefined; - children: PlainText; -}; -export type Image = ImageBase & { type: "image" }; -export type StrongImage = ImageBase & { type: "strongImage" }; -type ImageBase = { - unit: UnitBase; - fileId: string | undefined; - children: PlainText; -}; -export type Gyazo = GyazoBase & { type: "gyazo" }; -export type StrongGyazo = GyazoBase & { type: "strongGyazo" }; -type GyazoBase = { - unit: UnitBase; - children: PlainText; -}; -export type ImageLink = ImageLinkBase & { type: "imageLink" }; -export type StrongImageLink = ImageLinkBase & { type: "strongImageLink" }; -type ImageLinkBase = { - unit: UnitBase & { - image: string; - link: string; - }; - children: PlainText; -}; -export type GyazoLink = GyazoLinkBase & { type: "gyazoLink" }; -export type StrongGyazoLink = GyazoLinkBase & { type: "strongGyazoLink" }; -type GyazoLinkBase = { - unit: UnitBase & { - gyazo: string; - link: string; - }; - children: PlainText; -}; -export type Icon = IconBase & { type: "icon" }; -export type StrongIcon = IconBase & { type: "strong-icon" }; -type IconBase = { - unit: UnitBase & { - project?: string; - page: string; - size: number; - }; - children: PlainText; -}; -export type Formula = { - type: "deco-formula"; - unit: UnitBase & { - formula: string; - }; - children: PlainText; -}; -export type Strong = { - type: "strong"; - unit: UnitBase; - children: NodeWithoutIndent; -}; -export type Url = { - type: "url"; - unit: UnitBase; - fileId: string | undefined; - children: PlainText; -}; -export type UrlLink = { - type: "urlLink"; - unit: UnitBase & { - link: string; - title?: string; - }; - fileId: string | undefined; - children: PlainText; -}; -export type Youtube = { - type: "youtube"; - unit: - & UnitBase - & { - params: Record & { t?: number }; - } - & ({ - videoId?: string; - } | { - listId?: string; - }); - children: PlainText; -}; -export type GoogleMap = { - type: "location"; - unit: UnitBase & { - latitude: number; - longitude: number; - zoom: number; - title?: string; - }; - children: PlainText; -};