From 167e1cb8c7a694c9fec3d8ed0ae14082a74590f4 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Thu, 12 Aug 2021 21:22:54 +0900 Subject: [PATCH 1/7] :truck: move `Omit` to utils.ts --- scrapbox.ts | 6 ++---- utils.ts | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 utils.ts diff --git a/scrapbox.ts b/scrapbox.ts index cdcab3e..dc4e45c 100644 --- a/scrapbox.ts +++ b/scrapbox.ts @@ -1,9 +1,7 @@ -import type { ParsedLine } from "./line.ts"; +import { ParsedLine } from "./line.ts"; +import { Omit } from "./utils.ts"; export * from "./line.ts"; -// utilities -type Omit = Pick>; - /** scrapboxの行のメタデータ */ export interface Line { /** 行のid */ id: string; diff --git a/utils.ts b/utils.ts new file mode 100644 index 0000000..6a86a92 --- /dev/null +++ b/utils.ts @@ -0,0 +1,2 @@ +// utilities +export type Omit = Pick>; From 385e601b7327c3145950d50efc2f76d58b994fbc Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Thu, 12 Aug 2021 21:26:16 +0900 Subject: [PATCH 2/7] :truck: Moved types about `window.scrapbox` to userscript.ts --- scrapbox.ts | 116 ------------------------------------------------- userscript.ts | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 116 deletions(-) create mode 100644 userscript.ts diff --git a/scrapbox.ts b/scrapbox.ts index dc4e45c..97dc8e6 100644 --- a/scrapbox.ts +++ b/scrapbox.ts @@ -1,4 +1,3 @@ -import { ParsedLine } from "./line.ts"; import { Omit } from "./utils.ts"; export * from "./line.ts"; @@ -198,119 +197,4 @@ export type ProjectBackupWithMetadata = { }; }; -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; - }; - 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; - 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; -}; - -type TimeStamp = { - addFormat: (format: string | (() => string)) => void; - 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" - | "layout:changed" - | "project:changed"; diff --git a/userscript.ts b/userscript.ts new file mode 100644 index 0000000..ea28790 --- /dev/null +++ b/userscript.ts @@ -0,0 +1,118 @@ +import { ParsedLine } from "./line.ts"; + +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; + }; + 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; + 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; +}; + +type TimeStamp = { + addFormat: (format: string | (() => string)) => void; + 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" + | "layout:changed" + | "project:changed"; From 17b0a008e88d31371bac192d26f55d6cae8d29bb Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Thu, 12 Aug 2021 21:33:04 +0900 Subject: [PATCH 3/7] :truck: Moved types of parsed objects to userscript/*.ts --- scrapbox.ts | 5 ++- userscript.ts | 2 +- userscript/blocks.ts | 56 +++++++++++++++++++++++++++++++++ line.ts => userscript/nodes.ts | 57 +--------------------------------- 4 files changed, 60 insertions(+), 60 deletions(-) create mode 100644 userscript/blocks.ts rename line.ts => userscript/nodes.ts (80%) diff --git a/scrapbox.ts b/scrapbox.ts index 97dc8e6..1398654 100644 --- a/scrapbox.ts +++ b/scrapbox.ts @@ -1,5 +1,6 @@ import { Omit } from "./utils.ts"; -export * from "./line.ts"; +export * from "./userscript/blocks.ts"; +export * from "./userscript/nodes.ts"; /** scrapboxの行のメタデータ */ export interface Line { @@ -196,5 +197,3 @@ export type ProjectBackupWithMetadata = { lines: { text: string; updated: number; created: number }[]; }; }; - - diff --git a/userscript.ts b/userscript.ts index ea28790..6a5eec0 100644 --- a/userscript.ts +++ b/userscript.ts @@ -1,4 +1,4 @@ -import { ParsedLine } from "./line.ts"; +import { ParsedLine } from "./userscript/blocks.ts"; export type Layout = | "list" diff --git a/userscript/blocks.ts b/userscript/blocks.ts new file mode 100644 index 0000000..64ef814 --- /dev/null +++ b/userscript/blocks.ts @@ -0,0 +1,56 @@ +import { Node, NodeWithoutIndent } from "./nodes.ts"; + +export type ParsedLine = + & { + text: string; + id: string; + userId: string; + updated: number; + created: number; + section: { + number: number; + start: boolean; + end: boolean; + }; + } + & ({ + title?: boolean; + } | { + codeBlock: CodeBlock; + } | { + tableBlock: TableBlock; + } | { + helpfeel: Helpfeel; + } | { + cli: Cli; + } | { + formulaLine?: true; + nodes: NodeWithoutIndent[]; + } | { + numberList?: { digit: number }; + formulaLine?: true; + nodes: Node[]; + }); + +export type CodeBlock = { + lang: string; + filename?: string; + indent: number; + start: boolean; + end: boolean; +}; +export type TableBlock = { + title: string; + cells: string[]; + indent: number; + start: boolean; + end: boolean; +}; +export type Helpfeel = { + prefix: "?"; + entry: string; +}; +export type Cli = { + prefix: "$" | "%"; + command: string; +}; diff --git a/line.ts b/userscript/nodes.ts similarity index 80% rename from line.ts rename to userscript/nodes.ts index da09925..02d702f 100644 --- a/line.ts +++ b/userscript/nodes.ts @@ -1,58 +1,3 @@ -export type ParsedLine = - & { - text: string; - id: string; - userId: string; - updated: number; - created: number; - section: { - number: number; - start: boolean; - end: boolean; - }; - } - & ({ - title?: boolean; - } | { - codeBlock: CodeBlock; - } | { - tableBlock: TableBlock; - } | { - helpfeel: Helpfeel; - } | { - cli: Cli; - } | { - formulaLine?: true; - nodes: NodeWithoutIndent[]; - } | { - numberList?: { digit: number }; - formulaLine?: true; - nodes: Node[]; - }); - -export type CodeBlock = { - lang: string; - filename?: string; - indent: number; - start: boolean; - end: boolean; -}; -export type TableBlock = { - title: string; - cells: string[]; - indent: number; - start: boolean; - end: boolean; -}; -export type Helpfeel = { - prefix: "?"; - entry: string; -}; -export type Cli = { - prefix: "$" | "%"; - command: string; -}; - type NodeBase = | PlainText | Blank @@ -79,7 +24,7 @@ type NodeBase = | UrlLink | Youtube | GoogleMap; -type NodeWithoutIndent = NodeBase | Formula; +export type NodeWithoutIndent = NodeBase | Formula; export type Node = NodeWithoutIndent | Indent; type UnitBase = { content: string; From d655b64823df537845c2bd32f778c87c503de008 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Fri, 13 Aug 2021 10:08:16 +0900 Subject: [PATCH 4/7] :truck: Moved types about errrors to error.ts --- api/error.ts | 9 +++++++++ scrapbox.ts | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 api/error.ts diff --git a/api/error.ts b/api/error.ts new file mode 100644 index 0000000..9fe9f35 --- /dev/null +++ b/api/error.ts @@ -0,0 +1,9 @@ +export type NotMemberError = { + name: "NotMemberError"; + message: string; +}; + +export type NotFoundError = { + name: "NotFoundError"; + message: string; +}; diff --git a/scrapbox.ts b/scrapbox.ts index 1398654..1c91d0a 100644 --- a/scrapbox.ts +++ b/scrapbox.ts @@ -111,15 +111,6 @@ export interface Project { plan?: string; } -export type NotMemberError = { - name: "NotMemberError"; - message: string; -}; - -export type NotFoundError = { - name: "NotFoundError"; - message: string; -}; /** the response type of https://scrpabox.io/api/projects/:projectname */ export type ProjectResponse = From a35e9d8ef4a64bc9eb4fb6ba5293300ee54ae342 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Fri, 13 Aug 2021 10:22:16 +0900 Subject: [PATCH 5/7] :truck: Moved types about REST API responses to api/response.ts --- scrapbox.ts => api/response.ts | 16 +++------------- base.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 13 deletions(-) rename scrapbox.ts => api/response.ts (93%) create mode 100644 base.ts diff --git a/scrapbox.ts b/api/response.ts similarity index 93% rename from scrapbox.ts rename to api/response.ts index 1c91d0a..059b287 100644 --- a/scrapbox.ts +++ b/api/response.ts @@ -1,15 +1,6 @@ -import { Omit } from "./utils.ts"; -export * from "./userscript/blocks.ts"; -export * from "./userscript/nodes.ts"; - -/** scrapboxの行のメタデータ */ -export interface Line { - /** 行のid */ id: string; - /** 行のテキスト */ text: string; - /** 一番最後に行を編集した人のid */ userId: string; - /** 行の作成日時 */ created: number; - /** 行の最終更新日時 */ updated: number; -} +import { Omit } from "../utils.ts"; +import { Line } from "../base.ts"; +import { NotFoundError, NotMemberError } from "./error.ts"; /** 関連ページのメタデータ */ export interface RelatedPage { @@ -111,7 +102,6 @@ export interface Project { plan?: string; } - /** the response type of https://scrpabox.io/api/projects/:projectname */ export type ProjectResponse = | NotFoundError diff --git a/base.ts b/base.ts new file mode 100644 index 0000000..2e81319 --- /dev/null +++ b/base.ts @@ -0,0 +1,8 @@ +/** scrapboxの行のメタデータ */ +export interface Line { + /** 行のid */ id: string; + /** 行のテキスト */ text: string; + /** 一番最後に行を編集した人のid */ userId: string; + /** 行の作成日時 */ created: number; + /** 行の最終更新日時 */ updated: number; +} From 50a86009af2e4bd6483db19b2607791c3e4d74c6 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Fri, 13 Aug 2021 10:24:31 +0900 Subject: [PATCH 6/7] :sparkles: Exported all types from mod.ts --- mod.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 mod.ts diff --git a/mod.ts b/mod.ts new file mode 100644 index 0000000..167a6de --- /dev/null +++ b/mod.ts @@ -0,0 +1,5 @@ +export * from "./api/response.ts"; +export * from "./api/error.ts"; +export * from "./userscript.ts"; +export * from "./userscript/blocks.ts"; +export * from "./userscript/nodes.ts"; From d934b93d4273948306ab4687ab32f13bce8e3e38 Mon Sep 17 00:00:00 2001 From: takker99 <37929109+takker99@users.noreply.github.com> Date: Fri, 13 Aug 2021 10:24:44 +0900 Subject: [PATCH 7/7] :rotating_light: --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 9000357..faac222 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # types + scrapbox関連の型定義ファイル