Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# types

scrapbox関連の型定義ファイル
9 changes: 9 additions & 0 deletions api/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type NotMemberError = {
name: "NotMemberError";
message: string;
};

export type NotFoundError = {
name: "NotFoundError";
message: string;
};
144 changes: 3 additions & 141 deletions scrapbox.ts → api/response.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import type { ParsedLine } from "./line.ts";
export * from "./line.ts";

// utilities
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;

/** 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 {
Expand Down Expand Up @@ -113,16 +102,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 =
| NotFoundError
Expand Down Expand Up @@ -199,120 +178,3 @@ export type ProjectBackupWithMetadata = {
lines: { text: string; updated: number; created: number }[];
};
};

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";
8 changes: 8 additions & 0 deletions base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** scrapboxの行のメタデータ */
export interface Line {
/** 行のid */ id: string;
/** 行のテキスト */ text: string;
/** 一番最後に行を編集した人のid */ userId: string;
/** 行の作成日時 */ created: number;
/** 行の最終更新日時 */ updated: number;
}
5 changes: 5 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -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";
118 changes: 118 additions & 0 deletions userscript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { ParsedLine } from "./userscript/blocks.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";
56 changes: 56 additions & 0 deletions userscript/blocks.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Loading